let () =
  Scanf.scanf "%d %d" @@ fun n w ->
  let items = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
  let len = Array.fold_left (fun s (w,v) -> s+v) 1 items in
  let dp = Array.make len max_int in
  dp.(0) <- 0;
  for i = 0 to n-1 do
    let wi, vi = items.(i) in
    for j = len-1 downto vi do
      if dp.(j-vi) < max_int then
        dp.(j) <- min dp.(j) (dp.(j-vi) + wi)
    done;
  done;
  Array.mapi (fun i e -> i, e) dp
  |> Array.fold_left (fun a (v, wv) ->
      if wv <= w then v else a) 0
  |> Printf.printf "%d\n"