import qualified Data.IntMap.Strict as M
import Data.List

main = do
 [n,w] <- map read . words <$> getLine
 wvs <- map (map read . words) . lines <$> getContents
 print (knap n w wvs)

knap n w wvs = maximum $ M.elems $ foldl' dp (M.singleton 0 0) wvs
 where dp im [w',v'] = M.unionWith max im (M.filterWithKey (\k _ -> k<=w) $ M.mapKeys (+w') $ M.map (+v') im)