import Control.Applicative import Data.List solve :: Int -> [Int] -> Int solve l ws = last $ unfoldr (\x -> if sum (take x ws) <= l then Just (x,x+1) else Nothing) 0 main = do l <- (read :: String -> Int) <$> getLine n <- getLine ws <- fmap (read :: String -> Int) . words <$> getLine print $ solve l $ sort ws