module Main (main) where
import Data.Vector ((!), (!?), Vector)
import qualified Data.Vector as V
import Control.Applicative
main :: IO ()
main = do
  n:wmax:_ <- map read . words <$> getLine
  vws <- V.replicateM n $ do
    v:w:_ <- map read . words <$> getLine
    return (v,w)
  print $ V.maximum $ solve vws (wmax + 1)

solve :: Vector (Int,Int) -> Int -> Vector Int
solve vs maxw = V.foldl' f v0 vs
  where
    v0 = V.replicate maxw 0
    f :: Vector Int -> (Int,Int) -> Vector Int
    f prev (v,w) = new
      where
        new = V.generate maxw gen
        gen i = max v1 v2
          where
            v1 = case new !? (i - w) of
              Nothing -> 0
              Just k -> k + v
            v2 = prev ! i