import Data.List main = getLine >>= solve . read . last . words solve :: Int -> IO () solve m = getLine >>= print . length . fst . foldl (\(acc, b) x -> if x + b <= m then (x : acc, b + x) else (acc, b)) ([], 0) . sort . map read . words