var a,k: integer;
n, s: integer;
o, i: integer;
z: integer;
f: text;

begin
assign(f,'castle.in');
reset(f);
read(f,n,s);
z:=0;
for i:=1 to n do
begin
readln(f,a,k);
if (s>=a) then
begin
s:=s-a;
end else
begin
z:=z+a-s;
s:=0;
end;

writeln('a=',a,',s=',s,',z=',z);

end;
close(f);

assign(f,'castle.out');
rewrite(f);
writeln(f,z);
close(f);

end.