import Control.Applicative( (<$>))
import Control.Monad( replicateM)
import Data.List( sortBy)
import Data.Function( on)
import Data.Ratio( (%))

main = do
    [n_, w_] <- map read . words <$> getLine
    let
	object = do
	    [w,v] <- map read . words <$> getLine
	    return (w,v)
    
    os_ <- replicateM n_ object
    let
	cosperOrder = sortBy compare' os_
	  where
	    compare' (w1,v1) (w2,v2) = let
				cosper1 = v1%w1
				cosper2 = v2%w2
			    in
				if cosper1==cosper2
				then w2 `compare` w1
				else cosper2 `compare` cosper1


	insert values 0 _ = [values]
	insert values _ [] = [values]
	insert values slack ((w,v):os)
	  | w<=slack =
			let
			    ins = insert (values+v) (slack-w) os
			    non = insert values slack os
			in
			    concat [ins,non]

	  | otherwise = insert values slack os
    
    print . maximum $ insert 0 w_ cosperOrder