import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

solve :: Int -> Int -> [(Int, Int)] -> Int
solve n ww wvs = iter n ww
  where
    wva = listArray (1, n) wvs
    memo = listArray ((0, 0), (n, ww)) [iter i j | i <- [0..n], j <- [0..ww]]
    iter i j
        | i == 0    = 0
        | j <  wi   = memo ! (i - 1, j)
        | otherwise = max (memo ! (i, j - wi) + vi) (memo ! (i - 1, j))
      where
        (wi, vi) = wva ! i

main :: IO ()
main = do
    [n, w] <- fmap read . words <$> getLine :: IO [Int]
    wvs <- replicateM n $ do
        [v, w] <- fmap read . words <$> getLine :: IO [Int]
        return (w, v)
    print $ solve n w wvs
