let solve n w d =
  let v0 = Array.make (w + 1) 0 in
  let v1 = Array.make (w + 1) 0 in
  let rec doit = function
    | (i, _) when i > n -> v1.(w)
    | (i, x) when x > w ->
      Array.iteri (fun i e -> v0.(i) <- e) v1;
      doit (i + 1, 1)
    | (i, x) ->
      let (vi, wi) = d.(i-1) in
      v1.(x) <- if wi <= x && v0.(x-wi) + vi > v0.(x) then v0.(x-wi) + vi else v0.(x);
      doit (i, x + 1) in
  doit (1, 1)

let read () = Scanf.scanf "%d %d\n" (fun x y -> (x, y))

let () =
  let (n, w) = read () in
  let d = Array.init n (fun _ -> read ()) in
  Printf.printf "%d\n" (solve n w d)