import Control.Monad import Control.Applicative import Data.List main = do l <- readLn n <- readLn w <- map read . words <$> getLine -- [w] <- map read . words <$> getLine putStrLn . show $ solve l n w solve :: Int -> Int -> [Int] -> Int solve l n w = length . foldr (\x acc -> if x + sum acc <= l then x:acc else acc) [] . reverse $ sort w