
let () = Scanf.scanf "%d %d\n" @@ fun n wmax ->
  let wvs = Array.init n @@ fun _ ->
    Scanf.scanf "%d %d\n" @@ fun w v -> w, v in
  let vmax = Array.fold_right (fun (_, v) -> ( + ) v) wvs 0 in
  let dp = Array.make (1 + vmax) (1 + wmax) in
  dp.(0) <- 0;
  Array.iter (fun (w, v) ->
    for v' = vmax - v downto 0 do
      dp.(v + v') <- min dp.(v + v') (dp.(v') + w)
    done) wvs;
  try
    for v = vmax downto 0 do
      if dp.(v) <= wmax then begin
        Printf.printf "%d\n" v;
        raise Not_found
      end
    done
  with Not_found -> ()
