module Main (main) where
import Control.Applicative
import Control.Monad
getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  n:w:_ <- getInts
  xs <- replicateM n $ do
    v:w:_ <- getInts
    return (v,w)
  print $ solve w xs

solve :: Int -> [(Int,Int)] -> Int
solve _ [] = 0
solve w ((vi,wi):xs)
  | w >= wi   = (vi + solve (w - wi) xs)
                `max` solve w xs
  | otherwise = solve w xs