import Control.Applicative import Data.List main :: IO () main = do l <- readLn getLine print =<< solve l . sort . map read . words <$> getLine solve :: Int -> [Int] -> Int solve l lst = inner 0 lst where indicator x = if x then 1 else 0 inner _ [] = 0 inner acc (w:ws) = let acc' = acc + w in indicator (acc' <= l) + inner acc' ws