open System.Collections.Generic

let [|N;W|] = stdin.ReadLine().Split() |> Array.map int
let wv =
    [|1..N|]
    |> Array.map (fun _ -> stdin.ReadLine().Split() |> Array.map int)

wv
|> Array.scan (fun s [|w;v|] ->
    [|0..W|]
    |> Array.map (fun x ->
        if x >= w then max (s.[x-w]+int64(v)) (s.[x])
        else s.[x])) ([|0..W|] |> Array.map (fun _ -> 0L))
|> fun x -> x.[N].[W]
|> stdout.WriteLine