Uses
  Math;
Type
  mass=array[0..500000]of longint;
Var
  n,s,i,qq,mx:longint;
  a,k:mass;
  ans:int64;
  t,ind:mass;
Procedure Swap(Var a,b:longint);
Var
  c:longint;
Begin
  c:=a;
  a:=b;
  b:=c;
end;
Procedure qSort(Var m1,m2:mass;l,r:longint);
Procedure sort(l,r:longint);
Var
  i,j,sr,x1,x2:longint;
Begin
  i:=l;j:=r;
  sr:=i+random(j-i+1);
  x1:=m1[sr];
  x2:=m2[sr];
  repeat
    while (m1[i]<x1)or((m1[i]=x1)and(m2[i]<x2))do inc(i);
    while (x1<m1[j])or((x1=m1[j])and(x2<m2[j]))do dec(j);
    if i<=j then
      begin
        Swap(m1[i],m1[j]);
        Swap(m2[i],m2[j]);
        inc(i);dec(j);
      end;
  until i>j;
  if i<r then
    sort(i,r);
  if l<j then
    sort(l,j);
end;
Begin
  sort(l,r);
end;
Procedure build(v,tl,tr:longint);
Var
  tm:longint;
Begin
  if tl=tr then
    begin
      t[v]:=k[tl];
      ind[v]:=tl;
    end
  else
    begin
      tm:=(tl+tr)div 2;
      build(v*2,tl,tm);
      build(v*2+1,tm+1,tr);
      if t[v*2]>t[v*2+1] then
        begin
          t[v]:=t[v*2];
          ind[v]:=ind[v*2];
        end
      else
        begin
          t[v]:=t[v*2+1];
          ind[v]:=ind[v*2+1];
        end;
    end;
end;
Procedure update(v,tl,tr,ii,zn:longint);
Var
  tm:longint;
Begin
  if tl=tr then
    t[v]:=zn
  else
    begin
      tm:=(tl+tr)div 2;
      if ii<=tm then
        update(v*2,tl,tm,ii,zn)
      else
        update(v*2+1,tm+1,tr,ii,zn);
      if t[v*2]>t[v*2+1] then
        begin
          t[v]:=t[v*2];
          ind[v]:=ind[v*2];
        end
      else
        begin
          t[v]:=t[v*2+1];
          ind[v]:=ind[v*2+1];
        end;
    end;
end;
begin
//  assign(input,'input.txt');assign(output,'output.txt');
  assign(input,'castle.in');assign(output,'castle.out');
  readln(n,s);
  randomize;
  for i:=1 to n do
    begin
      readln(a[i],k[i]);
      if k[i]>a[i] then
        k[i]:=a[i];
    end;
  build(1,1,n);
  while 1=1 do
    begin
      if t[1]=0 then
        break;
      mx:=ind[1];
      qq:=a[mx] div k[mx];
      if qq>s then
        qq:=s;
      dec(a[mx],qq*k[mx]);
      dec(s,qq);
      if s=0 then
        break;
      if k[mx]>a[mx] then
        k[mx]:=a[mx];
      update(1,1,n,mx,k[mx]);
    end;
  ans:=0;
  for i:=1 to n do
    if a[i]>0 then
      ans:=ans+a[i];
  writeln(ans);
  {
  qSort(k,a,1,n);
  for i:=n downto 1 do
    begin
      qq:=a[i] div k[i];
      if qq>s then
        qq:=s;
      dec(a[i],k[i]*qq);
      dec(s,qq);
      if s=0 then
        break;
    end;
  if s>0 then
    begin
      qSort(a,k,1,n);
      for i:=n downto 1 do
        begin
          if a[i]>0 then
            qq:=1
          else
            qq:=0;
          if qq=1 then
            begin
              a[i]:=0;
              dec(a[i],min(a[i],k[i]));
              dec(s);
            end;
          if s=0 then
            break;
        end;
    end;
  ans:=0;
  for i:=1 to n do
    if a[i]>0 then
      ans:=ans+a[i];
  writeln(ans);}
end.
