import Control.Monad import Control.Applicative 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 0 w = 0 solve l n (x:xs) | l >= x = max (1 + (solve (l-x) (n-1) xs)) (solve l (n-1) xs) | otherwise = solve l (n-1) xs