var  w,h,u1,u2,d1,d2,i:integer;
begin
    read(w,h,u1,d1,u2,d2);
    for i:=h downto 1 do
        begin
            w:=w+i;
            if i=d1 then w:=w-u1;
            if i=d2 then w:=w-u2;
            if w<0 then w:=0;
        end;
    write(w);
end.

uses
Math;

var
  w, h, u1, d1, u2, d2, h_: Int32;

begin
  ReadLn(w, h);
  ReadLn(u1, d1);
  ReadLn(u2, d2);
  for h_ := h downto 0 do
  begin
    w += h_;
    if h_ = d1 then
    begin
      w := max(0, w - u1);
    end;
    if h_ = d2 then
    begin
      w := max(0, w - u2);
    end;
  end;
  WriteLn(w);
  ReadLn;
end.

Const fi='A1099.inp';
      fo='A1099.out';

Var n,h,x1,x2,y1,y2:longint;

Procedure       swap(var x,y:longint);
   var tmp:longint;
   begin
      tmp:=x; x:=y; y:=tmp;
   end;

Procedure       doc;
   begin
   {$ifndef ONLINE_JUDGE}
      assign(input,fi);    reset(input);
      assign(output,fo);   rewrite(output);
   {$endif}
      readln(n,h);
      readln(x1,y1);
      readln(x2,y2);
      if y1<y2 then begin swap(y1,y2); swap(x1,x2); end;
   end;

Procedure       process;
   begin
      inc(n,(h-y1+1)*(h+y1) div 2);
      dec(n,x1);
      if n<0 then n:=0;
      h:=y1-1;
      inc(n,(h-y2+1)*(h+y2) div 2);
      dec(n,x2);
      if n<0 then n:=0;
      h:=y2-1;
      inc(n,h*(h+1) div 2);
      write(n);
   end;

BEGIN
   doc;
   process;
END.

var i,w,h,u1,d1,u2,d2:longint;
begin
 read(w,h,u1,d1,u2,d2);
 if d1<d2 then begin
  i:=d1;d1:=d2;d2:=i;
   i:=u1;u1:=u2;u2:=i;
 end;
 if d2>h then begin write(h*(h+1) div 2+w ) ;halt; end;
 if d1<=h then begin for i:=h downto d1 do
 w:=w+i;
 w:=w-u1;
 if w<0 then w:=0;end else d1:=h+1;
 for i:=d1-1 downto d2 do
 w:=w+i;
 w:=w-u2;
 if w<0 then w:=0;for i:=d2-1 downto 0 do
 w:=w+i;
 write(w);
end.

const fi='';
      fo='';
var f:text;
    w,h,u1,d1,u2,d2:longint;

begin
  assign(f,fi);reset(f);
  readln(f,w,h);
  readln(f,u1,d1);
  readln(f,u2,d2);

  assign(f,fo);rewrite(f);
  while (h <> 0) do
        begin
          w:=w+h;
          if h=d1 then w:=w-u1;
          if h=d2 then w:=w-u2;
          if w < 0 then w:=0;
          dec(h);
        end;
  write(f,w);
  close(f);
end.

Var w,h,u1,u2,d1,d2:Longint;
Begin
    Readln(w,h);
    Readln(u1,d1);
    Readln(u2,d2);
    While h>0 do begin
        w:=w+h;
        If h=d1 then begin
            If w-u1<0 then w:=0 else w:=w-u1;
        End
        Else if h=d2 then begin
            If w-u2<0 then w:=0 else w:=w-u2;
        End;
        Dec(h);
    End;
    Writeln(w);
End.

var
 w,h,u1,d1,u2,d2,i,s:longint;
begin
 read(w,h,u1,d1,u2,d2);
 s:=0;
 for i:=h downto 1 do
  begin
   w:=w+i;
   if i=d1 then w:=w-u1;
   if i=d2 then w:=w-u2;
   if w<0 then w:=0;
  end;

 write(w);
end.

const fi='';
      fo='';
Var h,h1,h2,w,w1,w2: longint;
    f,g: text;
Begin
    Assign(f,fi); Reset(f);
    Assign(g,fo); Rewrite(g);
    Readln(f,w,h);
    Readln(f,w1,h1);
    Readln(f,w2,h2);
    While h<>0 do
        Begin
            If (h<>h1) and (h<>h2) then
                Begin
                    w:=w+h;
                    h:=h-1;
                End;
            If (h=h1) then
                Begin
                    w:=w+h;
                    w:=w-w1;
                    h:=h-1;
                    If w<0 then
                        w:=0;
                End;
            If (h=h2) then
                Begin
                    w:=w+h;
                    w:=w-w2;
                    h:=h-1;
                    If w<0 then
                        w:=0;
                End;
        End;
    Writeln(g,w);
    Close(f); Close(g);
End.

Program aProg;
var
	a, b, c, d, e, f:longint;
begin
	read(a, b, c, d, e, f);
	while b>0 do begin
		inc(a, b);
		if d=b then begin
			a-=c;
			if a<0 then a:=0;
		end;
		if f=b then begin
			a-=e;
			if a<0 then a:=0;
		end;
		dec(b);
	end;
	writeln(a);
end.

var
  w, h, u1, d1, u2, d2, i: integer;

begin
  readln(w, h);
  readln(u1, d1);
  readln(u2, d2);
  for i := h downto 1 do
  begin
    w := w + i;
    if i = d1 then w := w - u1;
    if i = d2 then w := w - u2;
    if w < 0 then w := 0;
  end;
  write(w);
end.

var
  w, h, u1, u2, d1, d2, i: integer;

begin
  read(w, h);
  read(u1, d1);
  read(u2, d2);
  for i := h downto 0 do
  begin
    w := w + i;
    if i = d1 then
      w := w - u1;
    if i = d2 then
      w := w - u2;
    if w < 0 then
      w := 0;
  end;
  write(w);
end.

var
 i,n,m,u,t:longint;
 a:array[1..100] of longint;
begin
  readln(n,m);
  for i:=1 to 2 do
    begin
      read(u,t);a[t]:=u;
    end;
  for i:=m downto 1 do
    begin
      inc(n,i);
      dec(n,a[i]);
      if n<0 then n:=0;
    end;
  writeln(n);
end.

const
        fi='';//'cf1099a.inp';
        fo='';//'cf1099a.out';
var
        w1,w2,w3,h1,h2,h3,i:longint;
begin
        assign(input,fi);reset(input);
        assign(output,fo);rewrite(output);
        readln(w1,h1);
        readln(w2,h2);
        readln(w3,h3);
        for i:=h1 downto 0 do
                begin
                        if i=h2 then w1:=w1-w2 else
                        if i=h3 then w1:=w1-w3;
                        w1:=w1+i;
                        if w1<0 then w1:=0;
                end;
        writeln(w1);
        close(input);
        close(output);
end.

program snignuykom;
   var w,w1,w2,d,d1,d2,i:longint;
begin
   readln(w,d);
   readln(w1,d1);
   readln(w2,d2);
   for i:=d downto 1 do
      begin
         w:=w+i;
         if i=d1 then w:=w-w1 else if i=d2 then w:=w-w2;
         if w<0 then w:=0;
      end;
   if w<0 then writeln(0) else writeln(w);
end.

var
 w,h,u1,d1,u2,d2,i : longint;

begin
 read(w,h,u1,d1,u2,d2);
 for i := h downto 1 do
  begin
   w := w + i;
   if (i = d1) then
    begin
     w := w - u1;
     if w < 0 then
      w := 0;
    end
   else if (i = d2) then
    begin
     w := w - u2;
     if w < 0 then
      w := 0;
    end;
  end;
 writeln(w);
end.

var  w,h,u1,u2,d1,d2,i:integer;
begin
    read(w,h,u1,d1,u2,d2);
    for i:=h downto 1 do begin
        w:=w+i;
        if i=d1 then w:=w-u1;
        if i=d2 then w:=w-u2;
        if w<0 then w:=0;
    end;
    write(w);
end.

var m,m1,m2,h,h1,h2,i:Integer;
 begin
  readln(m,h);
   readln(m1,h1);
    readln(m2,h2);
   for i:=h downto 0 do
     begin
     	m:=m+i;
       if i=h1 then m:=m-m1;
          if m<0 then m:=0;
        if i=h2 then m:=m-m2;
          if m<0 then m:=0;
              end;
      writeln(m);
 end.

Program p;
var h, h1, h2, w, w1, w2: integer;

begin
read(w, h, w1, h1, w2, h2);
for var g:=h downto 0 do
  begin
  w+=g;
  if g=h1 then w-=w1;
  if g=h2 then w-=w2;
  if w<0 then w:=0
  end;
write(w)
end.

var w, h, u1, d1, u2, d2, i:integer;

begin
readln(w, h);
readln(u1, d1);
readln(u2, d2);
for i:=h downto 0 do begin
if(i=d1) then w:=w-u1
else if(i=d2) then w:=w-u2;
w:=w+i;
if(w<0) then w:=0;
end;
writeln(w);
end.

var w,w1,w2,h,h1,h2,count:longint;

begin
    //assign(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    count:=h;
    while count>0 do
    begin
        inc(w,count);
        if count=h1 then
        begin
                dec(w,w1);
                if w<0 then w:=0;
        end;
        if count=h2 then
        begin
                dec(w,w2);
                if w<0 then w:=0;
        end;
          dec(count);
    end;
    //if w<0 then writeln(0) else
    writeln(w);

end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   while (h<>0) do
     begin
       w:=w+h;
       if h=d2 then w:=w-u2 else if h=d1 then w:=w-u1;
       h:=h-1;
       if w<0 then w:=0;
     end;
   writeln(w);
end.

var
w,h,u,d,v,b,x:int64;
i:longint;
begin

readln(w,h);
readln(u,d);
readln(v,b);
if d<b then begin
	x:=d;
	d:=b;
	b:=x;

	x:=u;
	u:=v;
	v:=x;
end;
for I:=h downto d do w:=w+i;
dec(w,u);
if w<0 then w:=0;

for I:=d-1 downto b  do w:=w+i;
dec(w,v);
if w<0 then w:=0;

for I:=b-1 downto 1  do w:=w+i;
writeln(w);
end.

var w, h, u1, d1, u2, d2, tmp, i: longint;
begin
readln(w, h);
readln(u1, d1);
readln(u2, d2);
if d2>d1 then
        begin
        tmp:=d2; d2:=d1; d1:=tmp;
        tmp:=u2; u2:=u1; u1:=tmp;
        end;
for i:=d1 to h do w:=w+i;
w:=w-u1; if w<0 then w:=0;
for i:=d2 to d1-1 do w:=w+i;
w:=w-u2; if w<0 then w:=0;
for i:=0 to d2-1 do w:=w+i;
writeln(w);
end.

var
w,h,d1,u1,d2,u2,i:integer;
begin
readln(w,h);
readln(u1,d1);
readln(u2,d2);
for i:=h downto 0 do
   begin
   w:=w+i;
   if i=d1 then begin
                w:=w-u1;
                if w<0 then w:=0;
                end;
   if i=d2 then begin
                w:=w-u2;
                if w<0 then w:=0;
                end;
   end;
write(w);
end.

var w, h, u1, u2, d1, d2, i:integer;
begin
 readln(w, h);
 readln(u1, d1);
 readln(u2, d2);
 for i:=h downto 0 do
  begin
   w+=i;
   if d1=i then w-=u1;
   if d2=i then w-=u2;
   if w<0 then w:=0;
  end;
 writeln(w);
end.

var
  w,h:integer;
  w1,h1,w2,h2:integer;
begin
  readln(w,h);
  readln(w1,h1);
  readln(w2,h2);
  for h:=h downto 0 do
  begin
    w+=h;
    if(h1 = h) then
    begin
      w:=w-w1;
      if(w<0)then w:=0;
    end;
    if(h2 = h) then
    begin
      w:=w-w2;
      if(w<0)then w:=0;
    end;
  end;
  writeln(w);
end.

var w,h,w1,d1,w2,d2,i:integer;
begin
 readln(w,h);
 readln(w1,d1);
 readln(w2,d2);

 for i:=h downto 1 do begin
  inc(w,i);
  if (i = d1) then
   w:=w-w1;
  if (i = d2) then
   w:=w-w2;
  if (w < 0) then
   w:=0;
 end;
 writeln(w);
end.

            const eps=0.0000000001;  besk1=200000008;  nnn=4600000;
            besk=8000000000000000000;
              modul={1000000007}998244353 ;

   label 22,1,2,3,4,33;
    type    real=extended;   double=extended;
    mas=array [-300000..nnn] of int64;   point=record x,y,z:real;end;
    zap=record p1,p2,p3,p4 :int64;end; zap1=^zap;
    mass=array[-10000..nnn] of longint;mass1=^mass;
    var tmin,aaa,bbb,ccc,kolst,kollek,aa,bb,t1,t2,kolx,koly,ans,ans1,ans2,dl,posleft,posright,n,xxx,yyy,dx,dy,m,w,h,jjj,l,r,cc,sum,mnog,nn,t3,t4,t5,t6,posmax,tmax,kold,kk,j2,ttt,ppp,kol,pmin,pmax,limit,posi,posj,diam,oldt,ot1,time,pos,ll,posx,posy,dloch,newdl,oldn,oldm,ost,ot,p1,p2,p3,p4,znamzz,kolperiod,znam,tperiod,start,finish,kol1,kol2,lavel,p0,jj,ii,ogr,q,p,pp,tt,oldtt,qq,qq1,qq2,q1,q2,imax,t,nm,smin,cen:int64;
   k,i2,i3,step2,k1,k2,pp0,mask,i1,j1,step1, step, i,j:longint;
   zz,numx,numy,xold,yold,x1,x0,d,xx,yy,b,a,zsum,y,x,z:array[-200000..1535002] of int64;

   gr:array[-1..2000,-1..2000] of boolean;

    prob1,prob2,prob3,pr1new,pr2new,pr3new,pr1,pr2,pr3:zap;
    iii,oldpos,finot,vv,znak:int64;
    aold:mas;  anss:zap;
    ss1,ss2:string;
    newstr,str,sss:array[-1000..20000] of string;
    lll,rrr,v,dist,alpha,phi:extended;
    zzz,ddnew,koef,polex,ddsum,dd:array[-1..440000,-1..30] of int64;
    ppos,mma,ma:array[-1000..2000005,-1..15] of int64;
    xleft,xright,xplus,xminus,px,py,xc,yc,xxc,yyc:extended;
    del:array[-1..100001,-1..20] of longint;
    z0,num,y1,z1,z2,kolnul,fact,next,prev,s,name,dnew, voltay,c,day:mas;
    zzzz:array[0..125000000] of byte;
    aaaa,bbbb,x2:extended;
    delit:array[0..100000,0..20] of longint;
    pole:array[-10..2002,-10..2005] of char;
    matr,ppole,ddl,ddr,dd3,dd4:array[-10..2000,-10..2200] of extended;
    ddnnew:array[-1..12,-1..12,0..200,0..3] of int64;
   newzan,marked,zanx,zany:array[-1000000..2000000] of boolean;
    ssold,sss1,sss2:string;
    def,stepen,koled,och,newoch,place,newnabor,stoim,nabor:array[-10..500005] of int64;
     zanleft,zanright,zan,fl:array[-100000..10000000] of boolean;
     dost:array[-1..210,-1..210,0..3,0..3] of int64;
    ss:string;ch,ch1,ch2:char;
    pr,hesh,numright,dr: array [-10..206000,-1..16] of int64;
    s3,s2,s1:array[-100..500000] of string;

    grr :array [-10..2010,-10..2010] of extended;
    maxpr:array[0..nnn] of string;
     tx,ty,vel,ott,v0,v1,s0,t0:int64;
     zv:point;
     left,right,ugol,rot,temp,sumtemp,vol,newx,newy:array[-1000..400000] of int64;
     mash,sqx,sqy,ottt:extended;
     xxxx,yyyy,yot:double;
       flag2,flag,flag1:boolean;

  function max(a,b:int64):int64;
begin max:=a; if b>a then max:=b;   end;

  function min(a,b:int64):int64;
begin min:=a; if b<a then min:=b;   end;

procedure udal(p:longint);
begin  next[prev[p]]:=next[p]; prev[next[p]]:=prev[p]; end;

      function nod(x,y:int64):int64; var z:int64;
begin   repeat  z:=x mod y;x:=y;y:=z;   until  z=0 ;  nod:=x;end;

     function summ(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p2+xx.p2*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=t1 div tt mod modul;
    t2:=t2 div tt mod modul;
    ott.p1:=t1; ott.p2:=t2;

   summ:=@ott;
 end;

     function prod(xx,yy:zap):zap1;
var t1,t2,tt:int64; ott:zap;
 begin
    t1:=(xx.p1*yy.p1) mod modul;
    t2:=(xx.p2*yy.p2) mod modul;
    tt:=nod(t1,t2);
    t1:=(t1 div tt) mod modul;
    t2:=(t2 div tt) mod modul;
    ott.p1:=t1; ott.p2:=t2;

   prod:=@ott;
 end;

    function al(x,y:real):real; var t0,t1,p,s0,s1:real;
 begin
     if (x>0)and(y>=0) then p:=arctan(y/x);
     if x<0 then p:=pi+arctan(y/x);
     if(x>0)and(y<0) then p:=2*pi+arctan(y/x);
     if x=0 then if (y>=0) then p:=pi/2 else p:=3*pi/2;
     al:=p{/pi*180};
 end;

function degg(a,k:int64):int64; var p:int64;
begin
 if k<=0 then degg:=1 else if odd(k) then degg:=degg(a,k-1)*a mod modul else
   begin  p:=degg(a,k shr 1); degg:=p*p mod modul;   end;

end;

function prost(tt:int64):boolean;
var aa:extended; i,p,t:longint;  fl:boolean;
 begin
   fl:=true;
   aa:=tt;
   aa:=sqrt(aa);
   t:=round(aa);
   for i:=2 to t do if tt mod i=0 then fl:=false;

   prost:=fl;
 end;

function arcsin(pp:extended):extended;
var tt:extended;
begin
   if (abs(pp)<=1+eps)and (abs(pp)>=1-eps)
   then if pp>0 then arcsin:=pi/2 else arcsin:=-pi/2;
   tt:=1-pp*pp;
   if abs(tt)>=0 then
     begin
        arcsin:=arctan(pp/sqrt(tt));

     end;

end;

function gl(ch:char):boolean;
begin
 if (ch='o')or (ch='a')or(ch='e')or(ch='u')or(ch='i') then gl:=true else gl:=false;

end;

function zaprmax(left,right:longint):int64;
begin
   if left>=right then zaprmax:=y[left] else
     begin
        if not odd(left) and odd(right) then zaprmax:=zaprmax(left shr 1,right shr 1) else
         begin
          if odd(left) then zaprmax:=max(zaprmax(left+1,right),y[left]);
          if not odd(right) then zaprmax:=max(zaprmax(left,right-1),y[right]);

         end;

     end;

end;

 function ff(gr:int64):boolean;

var ot,aa,bb,cc:int64; fl:boolean;
begin
  aa:=1; bb:=m;  cc:=aa; fl:=false;
  while abs(aa-bb)>1 do
    begin
       cc:=(aa+bb) shr 1;
       if y[cc]<gr then aa:=cc else bb:=cc;

    end;
   writeln(' cc= ',cc);
   cc:=min(cc+3,m+1);
   repeat dec(cc) until y[cc]<=gr;
   if y[cc]=gr then fl:=true else fl:=false;
  ff:=fl;
end;

begin
    { assign (input,'D:\Projects\input.txt');reset(input);
      assign (output,'D:\Projects\output.txt'); rewrite(output);
     }

     read(w,h);
     for i:=1 to 2 do read(a[i],b[i]);
     for i:=1 to 2 do x[b[i]]:=a[i];
     for step:=h downto 0 do
       begin
         w:=w+step;
         w:=max(w-x[step],0);
       {  writeln('h= ',step,' w = ',w);
        }

       end;

     writeln(w);

1:             close(output);
end.

var  w,h,u1,u2,d1,d2,i:integer;
begin
read(w,h,u1,d1,u2,d2);
for i:=h downto 1 do
begin
w:=w+i;
if i=d1 then w:=w-u1;
if i=d2 then w:=w-u2;
if w<0 then w:=0;
end;
write(w);
end.

var w,h,u1,d1,u2,d2,tempd,tempu,c:int64;
begin
        read(w,h,u1,d1,u2,d2);
        if d2>d1 then
        begin
            tempd:=d2;
            tempu:=u2;
            u2:=u1;
            d2:=d1;
            d1:=tempd;
            u1:=tempu;
        end;
        c:=w+h;
        while (h>d1) do
        begin
            dec(h);
            c:=c+h;
        end;
        c:=c-u1;
        if c<0 then c:=0;
        h:=d1;
        while (h>d2) do
        begin
            dec(h);
            c:=c+h;
        end;
        c:=c-u2;
        if c<0 then c:=0;
        h:=d2;
        while (h>0) do
        begin
            dec(h);
            c:=c+h;
        end;
        write(c);
end.

Program p1;
var mb,hb,m1,h1,m2,h2,i:integer;
begin
readln(mb,hb);
readln(m1,h1);
readln(m2,h2);
for i:=hb downto 0 do begin
                                         mb:=mb+i;
                                         if i=h1 then mb:=mb-m1;
                                         if i=h2 then mb:=mb-m2;
                                         if mb<0 then mb:=0;
                                         end;
write(mb);
end.

program a530_2;

uses
	math;

var
	w,h,d1,d2,u1,u2,i,t: longint;
	m:array[1..100] of longint;

begin
	readln(w,h,u1,d1,u2,d2);
	m[d1] := u1; m[d2] := u2;

	for i := h downto 1 do w := max(w + i - m[i], 0);
	writeln(w);
end.

var a,b,c,a1,b1,c1,i:longint;
begin
read(a,a1);
read(b,b1);
read(c,c1);
for i:=a1 downto 0 do
begin
if (i=b1) then a:=a-b+i
else if (i=c1) then a:=a-c+i
else a:=a+i;
if a<0 then a:=0;
end;
write(a);
end.

program loc;
type tabel= array [1..100] of integer;
var s:tabel;
    w,h,w1,h1,k,i:integer;
begin
readln(w,h);
for i:=1 to 2 do begin
readln(w1,h1);
s[h1]:=w1;
end;
for i:=h downto 0 do begin
w:=w+i;
w:=w-s[i];
if w<0 then w:=0;
end;
writeln(w);
end.

var
  ves, w, h, i, u1, d1, u2, d2: integer;

begin
  read(w, h, u1, d1, u2, d2);
  ves := w;
  for i := h downto 0 do
  begin
    ves := ves + i;
    if i = d1 then
    begin
      ves := ves - u1;
      if ves < 0 then
        ves := 0;
    end;
    if i = d2 then
    begin
      ves := ves - u2;
      if ves < 0 then
        ves := 0;
    end
  end;
  write(ves);
end.

Var i , w , w1 , w2 , h , h1 , h2 : Longint;

Function Max(x , y : Longint) : Longint;
    Begin
    If x > y then Exit(x) else Exit(y);
    End;

Procedure Check(x : Longint);
    Begin
    If x = h1 then
        Begin
        Dec(w , w1);
        w := Max(w , 0);
        Exit;
        End;
    If x = h2 then
        Begin
        Dec(w , w2);
        w := Max(w , 0);
        End;
    End;

Begin
    Readln(w , h);
    Readln(w1 , h1);
    Readln(w2 , h2);
    For i := h downto 0 do
        Begin
        Inc(w , i);
        Check(i);
        End;
    Writeln(w);
End.

var
	w, h, u1, d1, u2, d2: int64;

begin

	readln(w, h);
	readln(u1, d1);
	readln(u2, d2);

	for var i := h downto 1 do
	begin
		w += i;
		if (i = d1) then
			if (w > u1) then
				w -= u1
			else
				w := 0
		else if (i = d2) then
			if (w > u2) then
				w -= u2
			else
				w := 0;
	end;

	//if (w - u1 - u2 < 0) then
	//	writeln(0)
	//else
		writeln(w);

end.

var w,h,u1,i,d1,u2,d2: longint;

begin
  readln (w,h);
  readln (u1,d1);
  readln (u2,d2);
  for i:=h downto 1 do
  begin
    w:=w+i;
    if i=d1 then w:=max(0,w-u1);
    if i=d2 then w:=max(0,w-u2);
  end;
  writeln (w);
end.

var
  mc, hc, mm1, hm1, mm2, hm2,i,q: integer;

begin
  read(mc, hc, mm1, hm1, mm2, hm2);
  i:=hc;
  for q:=1 to hc do
  if (hc <> hm1) and (hc <> hm2) and (i>=0) then begin
    mc := mc + hc;
    hc := hc - 1;
    i:=i-1;
  end
  else begin
    if hc = hm1 then begin
      mc := mc + hm1;
      mc := mc - mm1;
      hc := hc - 1;
       i:=i-1;
    end;
    if hc = hm2 then begin
      mc := mc + hm2;
      mc := mc - mm2;
      hc := hc - 1;
       i:=i-1;
    end;
    if mc<0 then mc:=0;
  end;
  writeln(mc)
end.

const fi='';
      fo='';
var w,h,w1,h1,w2,h2:integer;

procedure docf;
var f:text;
begin
  assign(f,fi); reset(f);
  readln(f,w,h);
  readln(f,w1,h1);
  readln(f,w2,h2);
  close(f);
end;

procedure solve;
var f:text;
begin
  assign(f,fo); rewrite(f);
  while (h>0) do
  begin
    inc(w,h);
    if (h=h1) then dec(w,w1);
    if (h=h2) then dec(w,w2);
    if (w<0) then w:=0;
    dec(h);
  end;
  if (w<0) then writeln(f,0) else writeln(f,w);
  close(f);
end;

begin
  docf;
  solve;
end.

 var i,j,w,h,ww,hh:longint;
 a:array [0..101] of longint;
  begin
  read (w,h);
  read (ww,hh);
  a[hh]:=ww;
  read (ww,hh);
  a[hh]:=ww;

  for i:=h downto 1 do
   begin
    inc (w,i);
    dec (w,a[i]);
    if w<0 then w:=0;

   end;

   writeln (w);

  end.

var
 w,h,u1,u2,h1,h2,i:longint;
begin
 readln(w,h);
 readln(u1,h1);
 readln(u2,h2);
 for i:=h downto 0 do
  begin
   w:=w+i;
   if i=h1 then
    begin
     w:=w-u1;
     if w<0 then w:=0;
    end;
   if i=h2 then
    begin
     w:=w-u2;
     if w<0 then w:=0;
    end;
  end;
  writeln(w);
end.

var
w,h,u1,u2,d1,d2,i:integer;

begin
readln (w,h);
readln (u1,d1);
readln (u2,d2);

for i:=h downto 0 do begin
inc(w,i);
if i=d1 then dec (w,u1);
if i=d2 then dec (w,u2);
if w<0 then w:=0;
end;

write (w);

end.

Program Snowball;
var w,h,u1,d1,u2,d2:integer;

Begin
readln(w,h,u1,d1,u2,d2);
while h>0 do
  begin
    w:= w+h;
    if h=d1 then
      w:=w-u1;
    if h=d2 then
      w:=w-u2;
    if w<0 then
      w:=0;
    h:=h-1;
  end;
  writeln(w);
End.

var w,h,d1,d2,u1,u2,i,j,k:int64;
begin
read(w,h,u1,d1,u2,d2);
k:=w;
while h>=0 do
begin
if h=d1 then begin k:=max(k-u1+h,0) end else
if h=d2 then begin k:=max(k-u2+h,0)end else
k+=h;h-=1
end;
write(k)
end.

var w,h,u1,d1,u2,d2,i,a:integer;
begin
read(w,h,u1,d1,u2,d2);
for i:=h downto 1 do
begin
w:=w+i;
if (i=d1) then
w:=w-u1;
if (i=d2) then
w:=w-u2;
if (w<0) then
w:=0;
end;
write(w);
end.

Var
    w, h, u1, d1, u2, d2: Int64;

Begin
    Readln(w, h, u1, d1, u2, d2);
    For Var i := 0 to h do Begin
        w += (h - i);
        If (h - i) = d1 then
            w := max(0, w - u1)
        Else If (h - i) = d2 then
            w := max(0, w - u2)
    End;
    Write(max(0, w))
End.

var
  w, h, u1, u2, d1, d2: integer;

begin
  readln(w, h);
  readln(u1, d1);
  readln(u2, d2);
  while (h > 0) do
  begin
    w := w + h;
    if (h = d1) then w := w - u1;
    if (h = d2) then w := w - u2;
    h := h - 1;
    if w < 0 then w := 0;
  end;
  writeln(w);
end.

VAR
w,h,u1,u2,d1,d2:longint;
BEGIN
  read(w,h,u1,d1,u2,d2);
  for h:=h downto 0 do begin
    w += h;
    if h=d1 then w -= u1;
    if h=d2 then w -= u2;
    if w<0 then w:=0;
  end;
  write(w);
END.

var
  w, h, u1, u2, d1, d2, i: integer;

begin
  read(w, h);
  read(u1, d1);
  read(u2, d2);
  for i := h downto 0 do
  begin
    w := w + i;
    if i = d1 then
      w := w - u1;
    if i = d2 then
      w := w - u2;
  end;
  write(w);
end.

program snignuykom;
   var w,w1,w2,d,d1,d2,i:longint;
begin
   readln(w,d);
   readln(w1,d1);
   readln(w2,d2);
   for i:=1 to d do
      w:=w+i;
   w:=w-(w1+w2);
   if w<0 then writeln(0) else writeln(w);
end.

program snignuykom;
   var w,w1,w2,d,d1,d2,i:longint;
begin
   readln(w,d);
   readln(w1,d1);
   readln(w2,d2);
   for i:=1 to d do
      begin
         w:=w+i;
         if i=d1 then w:=w-w1 else if i=d2 then w:=w-w2;
         if w<0 then w:=0;
      end;
   if w<0 then writeln(0) else writeln(w);
end.

var h,h1,h2,m,m1,m2,c,i:integer;
begin
	readln(m,h);
	 readln(m1,h1);
	  readln(m2,h2);
 if h2>h1 then begin h1:=h1+h2; h2:=h1-h2; h1:=h1-h2; end;
  for i:=h1 to h do m:=m+i;
      m:=m-m1;
       if m<0 then m:=0;
  for i:=h2 to h1-1 do m:=m+i;
      m:=m-m2;
       if m<0 then m:=0;
        m:=m+(h2*(h2-1)div 2);
     writeln(m);
end.

var w, h, u1, d1, u2, d2, i:byte;

begin
readln(w, h);
readln(u1, d1);
readln(u2, d2);
for i:=h downto 0 do begin
if(i=d1) then w:=w-u1
else if(i=d2) then w:=w-u2;
w:=w+i;
if(w<0) then w:=0;
end;
writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then k:=1;
   while (h<>0) do
     begin
       if (k=1)and(h>=d2-1) then w:=w+h else if k<>1 then w:=w+h;
       if h=d2 then w:=abs(w-u2) else if h=d1 then w:=abs(w-u1);
       h:=h-1;
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then u1:=0;
   while (h<>0) do
     begin
       w:=w+h;
       if h=d2 then w:=abs(w-u2) else if h=d1 then w:=abs(w-u1);
       h:=h-1;
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then k:=1;
   while (h<>0) do
     begin
       if (k=1)and(h>=d2-1) then w:=w+h else if k<>1 then w:=w+h;
       if h=d2 then w:=w-u2 else if (h=d1)and(k<>1) then w:=w-u1;
       h:=h-1;
       if w<0 then w:=0;
       writeln(w,' -')
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   //if abs(d2-d1)>1 then u1:=0;
   while (h<>0) do
     begin
       w:=w+h;
       if h=d2 then w:=abs(w-u2) else if h=d1 then w:=abs(w-u1);
       h:=h-1;
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then k:=1;
   while (h<>0) do
     begin
       if (k=1)and(h>=d2-1) then w:=w+h else if k<>1 then w:=w+h;
       if h=d2 then w:=abs(w-u2) else if (h=d1)and(k<>1) then w:=abs(w-u1);
       h:=h-1;
       //writeln(w,' -')
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then k:=1;
   while (h<>0) do
     begin
       if (k=1)and(h>=d2-1) then w:=w+h else if k<>1 then w:=w+h;
       if h=d2 then w:=w-u2 else if (h=d1)and(k<>1) then w:=w-u1;
       h:=h-1;
       //if w<0 then w:=0;
       //writeln(w,' -')
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then u1:=0;
   while (h<>0) do
     begin
       w:=w+h;
       if h=d2 then w:=w-u2 else if h=d1 then w:=w-u1;
       h:=h-1;
       if w<0 then w:=0;
     end;
   writeln(w);
end.

var w,h,u1,u2,d1,d2,k : integer;
begin
    readln(w,h);
    readln(u1,d1);
    readln(u2,d2);
    if d1>d2 then
      begin
        k:=d1;
        d1:=d2;
        d2:=k;
        k:=u1;
        u1:=u2;
        u2:=k;
      end;
   k:=0;
   if abs(d2-d1)>1 then k:=1;
   while (h<>0) do
     begin
       if (k=1)and(h>=d2-1) then w:=w+h else if k<>1 then w:=w+h;
       if h=d2 then w:=w-u2 else if (h=d1)and(k<>1) then w:=w-u1;
       h:=h-1;
       if w<0 then w:=0;
       //writeln(w,' -')
     end;
   writeln(w);
end.

var w, h, u1, u2, d1, d2, i:integer;
begin
 readln(w, h);
 readln(u1, d1);
 readln(u2, d2);
 for i:=h downto 0 do
  begin
   w+=i;
   if d1=i then w-=u1;
   if d2=i then w-=u2;
  end;
 if w<0 then w:=0;
 writeln(w);
end.

Const fi='A1099.inp';
      fo='A1099.out';

Var n,h:longint;

Procedure       doc;
   var tmp:longint;
   begin
   {$ifndef ONLINE_JUDGE}
      assign(input,fi);    reset(input);
      assign(output,fo);   rewrite(output);
   {$endif}
      readln(n,h);
      readln(tmp); dec(n,tmp);
      readln(tmp); dec(n,tmp);
   end;

Procedure       process;
   begin
      inc(n,h*(h+1) div 2);
      if n<0 then write(0) else write(n);
   end;

BEGIN
   doc;
   process;
END.

Const fi='A1099.inp';
      fo='A1099.out';

Var n,h,x1,x2,y1,y2:longint;

Procedure       swap(var x,y:longint);
   var tmp:longint;
   begin
      tmp:=x; x:=y; y:=tmp;
   end;

Procedure       doc;
   begin
   {$ifndef ONLINE_JUDGE}
      assign(input,fi);    reset(input);
      assign(output,fo);   rewrite(output);
   {$endif}
      readln(n,h);
      readln(x1,y1);
      readln(x2,y2);
      if y1<y2 then begin swap(y1,y2); swap(x1,x2); end;
   end;

Procedure       process;
   begin
      inc(n,(h-y1+1)*(h+y1) div 2);
      dec(n,x1);
      if n<0 then n:=0;
      h:=y1-1;
      inc(n,(h-y2+1)*(h+y2) div 2);
      dec(n,x2);
      if n<0 then n:=0;
      write(n);
   end;

BEGIN
   doc;
   process;
END.

var i,w,h,u1,d1,u2,d2:longint;
begin
 read(w,h,u1,d1,u2,d2);
 if d1<d2 then begin
  i:=d1;d1:=d2;d2:=1;
   i:=u1;u1:=u2;u2:=1;
 end;
 for i:=h downto d1 do
 w:=w+i;
 w:=w-u1;
 if w<0 then w:=0;
 for i:=d1-1 downto d2 do
 w:=w+i;
 w:=w-u2;
 if w<0 then w:=0;for i:=d2-1 downto 0 do
 w:=w+i;
 write(w);
end.

const fi='';
      fo='';
var f:text;
    w,h,u1,d1,u2,d2:longint;

begin
  assign(f,fi);reset(f);
  readln(f,w,h);
  readln(f,u1,d1);
  readln(f,u2,d2);

  assign(f,fo);rewrite(f);
  while (h <> 0) do
        begin
          w:=w+h;
          dec(h);
        end;
  if w-u1-u2 < 0 then write(f,0) else write(f,w-u1-u2);
  close(f);
end.

const fi='';
      fo='';
var f:text;
    w,h,u1,d1,u2,d2:longint;

begin
  assign(f,fi);reset(f);
  readln(f,w,h);
  readln(f,u1,d1);
  readln(f,u2,d2);

  assign(f,fo);rewrite(f);
  while (h <> 0) do
        begin
          w:=w+h;
          dec(h);
        end;
  write(f,w-u1-u2);
  close(f);
end.

var
 w,h,u1,d1,u2,d2,i,s:longint;
begin
 read(w,h,u1,d1,u2,d2);
 s:=0;
 for i:=h downto 0 do
  begin
   if i=d1 then w:=w-u1+i
    else if i=d2 then w:=w-u2+i
     else w:=w+i;
  end;
 if w<0 then w:=0;
 write(w);
end.

var
 w,h,u1,d1,u2,d2,i,s:longint;
begin
 read(w,h,u1,d1,u2,d2);
 s:=0;
 for i:=h downto 1 do
  begin
   if i=d1 then w:=w-u1+i
    else if i=d2 then w:=w-u2+i
     else w:=w+i;
  end;
 if w<0 then w:=0;
 write(w);
end.

var
 w,h,u1,d1,u2,d2,i,s:longint;
begin
 read(w,h,u1,d1,u2,d2);
 s:=0;
 for i:=h downto 0 do
  begin
   w:=w+i;
   if i=d1 then w:=w-u1;
   if i=d2 then w:=w-u2;
  end;
 if w<0 then w:=0;
 write(w);
end.

Const   fi='';
        fo='';
Var  f,g:text;
     w,h,u1,d1,u2,d2,s1,s2,k:longint;

Begin
  Assign(f,fi);Reset(f);
  Assign(g,fo);Rewrite(g);
  Readln(f,w,h);
  Readln(f,u1,d1);
  Readln(f,u2,d2);
   k:= h-d1-d2;
        w:=w+h;
        h:=h-1;
        w:=w+h;
        w:=w-u1;
        h:=h-1;
        w:=w+h;
        w:=w-u2;
        h:=h-1;
        w:=w+h;
        s1:=w;
   If k=0 then  writeln(g,s1);
   If k>0 then begin
     while (k<>0) do
        begin
        k:=k-1;
         s2:=s1+k;

        end;
        writeln(g,s2);
     end;

  close(f);
  close(g);
end.

Const   fi='';
        fo='';
Var  f,g:text;
     w,h,u1,d1,u2,d2,s1,s2,k:longint;

Begin
  Assign(f,fi);Reset(f);
  Assign(g,fo);Rewrite(g);
  Readln(f,w,h);
  Readln(f,u1,d1);
  Readln(f,u2,d2);
  While (h<>0) do
    begin
        w:=w+h;
        h:=h-1;
        w:=w+h;
        If (w-u1<0) then w:=0
          else w:=w-u1;
          u1:=0;
        h:=h-1;
        w:=w+h;
       If (w-u2<0) then w:=0
          else w:=w-u2;
          u2:=0;

        If (h-1>0) then h:=h-1
           else h:=0;
        w:=w+h;
     end;
       writeln(g,w);

  close(f);
  close(g);
end.

Const   fi='';
        fo='';
Var  f,g:text;
     w,h,u1,d1,u2,d2,s1,s2,k:longint;

Begin
  Assign(f,fi);Reset(f);
  Assign(g,fo);Rewrite(g);
  Readln(f,w,h);
  Readln(f,u1,d1);
  Readln(f,u2,d2);
   k:= h-d1-d2;
        w:=w+h;
        h:=h-1;
        w:=w+h;
        w:=w-u1;
        h:=h-1;
        w:=w+h;
        w:=w-u2;
        h:=h-1;
        w:=w+h;
        s1:=w;
   If k=0 then  writeln(g,s1);
   If k>0 then begin
     while (k<>0) do
        begin
         k:=k-1;
         s1:=s1+k;
        end;
        writeln(g,s1);
     end;

  close(f);
  close(g);
end.

Const   fi='';
        fo='';
Var  f,g:text;
     w,h,u1,d1,u2,d2,s1,s2,k:longint;

Begin
  Assign(f,fi);Reset(f);
  Assign(g,fo);Rewrite(g);
  Readln(f,w,h);
  Readln(f,u1,d1);
  Readln(f,u2,d2);
   k:= h-d1-d2;
        w:=w+h;
        h:=h-1;
        w:=w+h;
        w:=w-u1;
        h:=h-1;
        w:=w+h;
        w:=w-u2;
        h:=h-1;
        w:=w+h;
        s1:=w;
   If k=0 then  writeln(g,s1);
   If k>0 then begin
     while (k<>0) do
        begin
         s2:=s1+k;
         k:=k-1;
        end;
        writeln(g,s2);
     end;

  close(f);
  close(g);
end.

Const   fi='';
        fo='';
Var  f,g:text;
     w,h,u1,d1,u2,d2,s1,s2,k:longint;

Begin
  Assign(f,fi);Reset(f);
  Assign(g,fo);Rewrite(g);
  Readln(f,w,h);
  Readln(f,u1,d1);
  Readln(f,u2,d2);
   k:= h-d1-d2;
        w:=w+h;
        h:=h-1;
        w:=w+h;
        If (w-u1<0) then w:=0
          else w:=w-u1;
        h:=h-1;
        w:=w+h;
       If (w-u2<0) then w:=0
          else w:=w-u2;
        h:=h-1;
        w:=w+h;
        s1:=w;
   If k=0 then  writeln(g,s1);
   If k>0 then begin
     while (k<>0) do
        begin
         k:=k-1;
         s1:=s1+k;
        end;
        writeln(g,s1);
     end;

  close(f);
  close(g);
end.

Var  w,h,u1,d1,u2,d2,s:longint;

Begin
  Readln(w,h);
  Readln(u1,d1);
  Readln(u2,d2);
  s:= (w-u1) + (h+d1) + d2 -u2;
  writeln(s);
  end.

var
 i,n,m,u:longint;
 a:array[1..100] of longint;
begin
  readln(n,m);
  for i:=1 to 2 do
    begin
      read(u);readln(a[u]);
    end;
  for i:=n downto 1 do
    begin
      inc(n,i);
      dec(n,a[i]);
      if n<0 then n:=0;
    end;
  writeln(n);
end.

var
 w,h,u1,d1,u2,d2,i : longint;

begin
 read(w,h,u1,d1,u2,d2);
 for i := h downto 1 do
  begin
   w := w + i;
   if (i = d1) then
    w := w - u1
   else if (i = d2) then
    w := w - u2;
  end;
 if w < 0 then
  w := 0;
 writeln(w);
end.

var w,w1,w2,h,h1,h2:longint;

procedure swap(var a,b:longint);
var c:longint;
begin
    c:=a;
    a:=b;
    b:=c;
end;

begin
    //assign(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    if h1<h2 then
    begin
        swap(w1,w2);
        swap(h1,h2);
    end;
    w:=w+h-w1+h1-w2+h2;
    writeln(w);

end.

var w,w1,w2,h,h1,h2,count:longint;

begin
    //assign(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    w:=w-w1-w2;
    if w<0 then w:=0;
    count:=h;
    while count>0 do
    begin
        inc(w,count);
        dec(count);
    end;
    if w<0 then writeln(0) else writeln(w);

end.

var w,w1,w2,h,h1,h2,count:longint;

procedure swap(var a,b:longint);
var c:longint;
begin
    c:=a;
    a:=b;
    b:=c;
end;

begin
    //(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    if h1<h2 then
    begin
        swap(w1,w2);
        swap(h1,h2);
    end;
    w:=w+h-w1+h1-w2+h2;
    count:=h;
    while count>0 do
    begin
        dec(count);
        if (count<>h1) and (count<>h2) then w:=w+count;
    end;
    if w<0 then writeln(0) else writeln(w);

end.

var w,w1,w2,h,h1,h2,count:longint;

begin
    //assign(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    w:=w-w1-w2;
    count:=h;
    while count>0 do
    begin
        inc(w,count);
        dec(count);
    end;
    if w<0 then writeln(0) else writeln(w);

end.

var w,w1,w2,h,h1,h2:longint;

procedure swap(var a,b:longint);
var c:longint;
begin
    c:=a;
    a:=b;
    b:=c;
end;

begin
    //assign(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    if h1<h2 then
    begin
        swap(w1,w2);
        swap(h1,h2);
    end;
    w:=w+h-w1+h1-w2+h2;
    if w<0 then writeln(0) else writeln(w);

end.

var w,w1,w2,h,h1,h2,count:longint;

begin
    //assign(input,'BONUS.inp');reset(input);
    //assign(output,'BONUS.out');rewrite(output);
    readln(w,h);
    readln(w1,h1);
    readln(w2,h2);
    w:=w+h-w1-w2;
    count:=h;
    while count>0 do
    begin
        dec(count);
        inc(w,count);
    end;
    if w<0 then writeln(0) else writeln(w);

end.

var  w,h,u1,u2,d1,d2,i:integer;
begin
read(w,h,u1,d1,u2,d2);
for i:=h downto 1 do
begin
w:=w+i;
if i=d1 then w:=w-u1;
if i=d2 then w:=w-u2;
if i<0 then w:=0;
end;
write(w);
end.

var w,h,u1,d1,u2,d2,c:int64;
begin
        read(w,h,u1,d1,u2,d2);
        c:=w+h+d1-u1;
        if c<0 then c:=0;
        c:=c+d2-d1-u2;
        if c<0 then c:=0;
        write(c+1);
end.

var w,h,u1,d1,u2,d2,tempd,tempu,c:int64;
begin
        read(w,h,u1,d1,u2,d2);
        if d2>d1 then
        begin
            tempd:=d2;
            tempu:=u2;
            u2:=u1;
            d2:=d1;
            d1:=tempd;
            u1:=tempu;
        end;
        c:=w+h;
        while (h>d1) do
        begin
            dec(h);
            c:=c+h;
        end;
        c:=c-u1;
        if c<0 then c:=0;
        h:=d1;
        while (h>d2) do
        begin
            dec(h);
            c:=c+h;
        end;
        c:=c-u2;
        if c<0 then write(0) else write(c);

end.

var a,b,c,a1,b1,c1,i:longint;
begin
read(a,a1);
read(b,b1);
read(c,c1);
for i:=a1 downto 0 do
begin
if i=b1 then a:=a-b
else a:=a+i;
if a<0 then a:=0;
end;
write(a);
end.

Var n , h , i , tmp1 , tmp2 , tmp , kq : Longint;
Begin
Readln(n , h);
kq := n + h*(h+1) div 2;
For i := 1 to 2 do
    Begin
    Readln(tmp1 , tmp2);
    Dec(kq , tmp1);
    End;
Writeln(kq);
End.

Var n , h , i , tmp1 , tmp2 , tmp , kq : Longint;
Begin
Readln(n , h);
kq := n + h*(h+1) div 2;
For i := 1 to 2 do
    Begin
    Readln(tmp1 , tmp2);
    Dec(kq , tmp1);
    End;
If kq > 0 then Writeln(kq) else Writeln('0');
End.

const fi='';
      fo='';
var w,h,w1,h1,w2,h2:integer;

procedure docf;
var f:text;
begin
  assign(f,fi); reset(f);
  readln(f,w,h);
  readln(f,w1,h1);
  readln(f,w2,h2);
  close(f);
end;

procedure solve;
var f:text;
begin
  assign(f,fo); rewrite(f);
  while (h>0) do
  begin
    inc(w,h);
    if (h=h1) then dec(w,w1);
    if (h=h2) then dec(w,w2);
    dec(h);
  end;
  if (w<0) then writeln(f,0) else writeln(f,w);
  close(f);
end;

begin
  docf;
  solve;
end.

var
 w,h,u1,u2,h1,h2,i:longint;
begin
 readln(w,h);
 readln(u1,h1);
 readln(u2,h2);
 for i:=h downto 0 do
  begin
   h:=h+i;
   if i=h1 then
    begin
     w:=w-u1;
     if w<0 then w:=0;
    end;
   if i=h2 then
    begin
     w:=w-u2;
     if w<0 then w:=0;
    end;
  end;
  writeln(w);
end.

var
 w,h,u1,u2,h1,h2,i:longint;
begin
 readln(w,h);
 readln(u1,h1);
 readln(u2,h2);
 for i:=h downto 1 do
  begin
   h:=h+i;
   if i=h1 then
    begin
     w:=w-u1;
     if w<0 then w:=0;
    end;
   if i=h2 then
    begin
     w:=w-u2;
     if w<0 then w:=0;
    end;
  end;
  writeln(w);
end.

var
	w, h, u1, d1, u2, d2: int64;

begin

	readln(w, h);
	readln(u1, d1);
	readln(u2, d2);

	for var i := h downto 1 do
	begin
		w += i;
	end;

	writeln(w - u1 - u2);

end.

var
	w, h, u1, d1, u2, d2: int64;

begin

	readln(w, h);
	readln(u1, d1);
	readln(u2, d2);

	for var i := h downto 1 do
	begin
		w += i;
	end;

	if (w - u1 - u2 < 0) then
		writeln(0)
	else
		writeln(w - u1 - u2);

end.

var
  mc, hc, mm1, hm1, mm2, hm2,i,q: integer;

begin
  read(mc, hc, mm1, hm1, mm2, hm2);
  i:=hc;
  for q:=1 to hc do
  if (hc <> hm1) and (hc <> hm2) and (i<>0) then begin
    mc := mc + hc;
    hc := hc - 1;
    i:=i-1;
  end
  else begin
    if hc = hm1 then begin
      mc := mc + hm1;
      mc := mc - mm1;
      hc := hc - 1;
       i:=i-1;
    end;
    if hc = hm2 then begin
      mc := mc + hm2;
      mc := mc - mm2;
      hc := hc - 1;
       i:=i-1;
    end;
  end;
  writeln(mc)
end.

var
  mc, hc, mm1, hm1, mm2, hm2,i,q: integer;

begin
  read(mc, hc, mm1, hm1, mm2, hm2);
  i:=hc;
  for q:=1 to hc do
  if (hc <> hm1) and (hc <> hm2) and (i>=0) then begin
    mc := mc + hc;
    hc := hc - 1;
    i:=i-1;
  end
  else begin
    if hc = hm1 then begin
      mc := mc + hm1;
      mc := mc - mm1;
      hc := hc - 1;
       i:=i-1;
    end;
    if hc = hm2 then begin
      mc := mc + hm2;
      mc := mc - mm2;
      hc := hc - 1;
       i:=i-1;
    end;
  end;
  writeln(mc)
end.

var
w,h,u1,u2,d1,d2:integer;

begin
readln (w,h);
readln (u1,d1);
readln (u2,d2);
inc (w,h);
while h>max(d1,d2) do begin
dec(h);
inc(w,h);
end;

if h=max(d1,d2) then begin
 if max(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 while h>min(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=min(d1,d2) then begin
 if min(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 write (w);end.

var
w,h,u1,u2,d1,d2:integer;

begin
readln (w,h);
readln (u1,d1);
readln (u2,d2);
inc (w,h);
while h>max(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=max(d1,d2) then begin
 if max(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 while h>min(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=min(d1,d2) then begin
 if min(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   //if w<0 then w:=0;

 write (w);end.

var
w,h,u1,u2,d1,d2:integer;

begin
readln (w,h);
readln (u1,d1);
readln (u2,d2);
if h<>max(d1,d2) then
inc (w,h);
while h>max(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=max(d1,d2) then begin
 if max(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 while h>min(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=min(d1,d2) then begin
 if min(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 write (w);end.

var
w,h,u1,u2,d1,d2:integer;

begin
readln (w,h);
readln (u1,d1);
readln (u2,d2);
inc (w,h);
while h>max(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=max(d1,d2) then begin
 if max(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 while h>min(d1,d2) do begin
dec (h);
inc(w,h);
end;

if h=min(d1,d2) then begin
 if min(d1,d2)=d1 then
 dec (w,u1) else
 dec (w,u2);
 end;
   if w<0 then w:=0;

 write (w);end.