module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

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
  Array.fold_left (fun m (w, v) ->
    IntMap.fold (fun w' v' m ->
      if wmax < w + w' then m
      else IntMap.add (w + w') (max (v + v') @@
        try IntMap.find (w + w') m with Not_found -> min_int) m) m m) (IntMap.singleton 0 0) wvs
  |> (fun m -> IntMap.fold (fun _ -> max) m min_int)
  |> Printf.printf "%d\n"
