import qualified Data.ByteString.Char8 as B
import Data.List
import qualified Data.Vector.Unboxed as V
readIntPair :: B.ByteString -> (Int,Int)
readIntPair s = p
    where
    Just p = do
        (n1, s') <- B.readInt s
        (n2, _ ) <- B.readInt (B.tail s')
        return (n1,n2)

main :: IO ()
main = do
    (_,w_limit) <- fmap readIntPair B.getLine
    items <- fmap (map readIntPair . B.lines) B.getContents 
    let v_end = V.maximum $ foldl' step s0 items
        step :: V.Vector Int -> (Int, Int) -> V.Vector Int
        step tbl (wi, vi) = tbl'
            where
            tbl' = V.generate (w_limit+1) $ \i -> 
                    max (tbl V.! i) (if i >= wi then tbl V.! (i - wi) + vi else 0)
        s0 = V.generate (w_limit+1) $ \_ -> 0
    print (v_end :: Int)
    
