import Control.Applicative import Control.Monad import Data.List solve :: Int -> [Int] -> Int solve c ai = head $ f c (sortBy (flip compare) ai) 0 ++ [-1] where f rest [] ans = do guard (rest == 0) return ans f rest (x:xs) ans = do let m = rest `div` x i <- [m,m-1..0] f (rest - i*x) xs (ans + i) main :: IO () main = do c <- readLn :: IO Int n <- readLn :: IO Int ai <- map read . words <$> getLine :: IO [Int] print $ solve c ai