var
  q, w, ee, e, n, s, i, j,sum: longint;
  a, aa: array[1..100]of integer;
  t: text;

begin
  assign(t, 'castle.in');
  reset(t);
  readln(t, n, s);
  e := 1;
  ee := 1;
  for i := 1 to n do
  begin
    readln(t, q, w);
    inc(sum,q);
    if w = 1 then
    begin a[e] := q;inc(e) end else 
    begin aa[ee] := q;inc(ee);  end;
  end;
  for i := 1 to ee do
  begin
    if s >= aa[i] - aa[i] mod 2 then 
    begin
      dec(s, (aa[i] - aa[i] mod 2)mod 2);
      dec(aa[i], aa[i] - aa[i] mod 2);
      dec(sum,aa[i] - aa[i] mod 2)
    end;
    if s=0 then break;
  end;
  
  
  close(t);
  assign(t, 'castle.out');
  rewrite(t);
  if sum<s then write(t,0)else writeln(t,sum-s);
  close(t);
end.