import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,maxW] <- getIntList
    items <- replicateM n $ do
        [w,v] <- getIntList
        return (w,v)
    let mV = sum $ map snd items
    print . pred . VU.length . VU.filter (<= maxW) . VU.scanr min 1000000000 $ solve mV items

solve mV [] = VU.create $ do
    vec <- VUM.replicate (mV+1) 10000
    VUM.write vec 0 0
    return vec
solve mV ((w,v):xs) 
  = let a = solve mV xs 
    in VU.generate (mV+1)
      $ \i -> if v <= i then
                  min (a VU.! i) (a VU.! (i-v) + w)
              else a VU.! i