import Data.Array.IArray
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main = do
    [n,w] <- map read . words <$> getLine :: IO [Int]
    wv <- map ((\[a,b] -> (a,b)) . map (fst . fromJust . BS.readInt) . BS.words) . BS.lines <$> BS.getContents
    print $ knapsack w wv

knapsack :: Int -> [(Int,Int)] -> Integer
knapsack c wv = memo!(n,c)
  where
    n = length wv
    k = ((0,0),(n,c))
    memo = listArray k [f t | t <- range k] :: Array (Int,Int) Integer
    f :: (Int,Int) -> Integer
    f (i,ci)
      | i == 0 = 0
      | wi > ci = memo!(i-1, ci)
      | otherwise = maximum [vi + memo!(i-1, ci-wi), memo!(i-1, ci)]
      where
        wv' = listArray (1, n) wv :: Array Int (Int, Int)
        wi = fromIntegral $ fst (wv'!i)
        vi = fromIntegral $ snd (wv'!i)