import Control.Monad
import Data.Vector.Unboxed hiding (map, replicateM)

solve n goods w = f 0 w where
  f i j
    | i == n = 0
    | j < wi = f (i+1) j
    | otherwise = max (f (i+1) j) (f (i+1) (j-wi) + vi)
    where (wi, vi) = gvec ! i
  gvec = fromList goods

main = do
  [n,w] <- map read.words <$> getLine
  goods <- replicateM n $ (\[a,b]->(a,b)).map read.words <$> getLine
  print $ solve n goods w
