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 dp = Array.make (w+1) 0 in
  for i = 0 to n-1 do
    let wi, vi = items.(i) in
    for j = w downto wi do
      dp.(j) <- max dp.(j) (dp.(j-wi) + vi)
    done;
  done;
  Printf.printf "%d\n" dp.(w)