import qualified Data.IntMap as M

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

knap n w wvs = fst $ M.findMax $ foldr dp (M.singleton 0 0) wvs
 where dp [w',v'] im = M.unionWith min im (M.mapKeys (+v') $ M.filter (<=w) $ M.map (+w') im)