let solve n w d =
  let t = Array.make (w + 1) 0 in
  let rec doit = function
    | (i, _) when i = n -> Array.fold_left max min_int t
    | (i, x) when x = w -> doit (i + 1, 0)
    | (i, x) ->
      let (vi, wi) = d.(i) in
      if x + wi <= w then t.(x+wi) <- max t.(x+wi) (t.(x) + vi);
      doit (i, x + 1) in
  doit (0, 0)

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)