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 dp = Array.make (wmax + 1) 0 in
  Array.iter (fun (w, v) ->
    for w' = wmax - w downto 0 do
      dp.(w + w') <- max dp.(w + w') (v + dp.(w'))
    done) wvs;
  Printf.printf "%d\n" @@ Array.fold_left max min_int dp
