import Control.Applicative
import qualified Data.IntMap as Map

main = do
  [target,_] <- map (read :: String -> Int) . words <$> getLine
  coins <- map (read :: String -> Int) . words <$> getLine
  print $ (resolve target coins (Map.fromList (zip [0..target] [0,0..]))) Map.! target

resolve :: Int -> [Int] -> Map.IntMap Int -> Map.IntMap Int
resolve target (n:ns) tagMap
  |null ns   = dp n tagMap
  |otherwise = resolve target ns (dp n tagMap)
  where
    dp :: Int -> Map.IntMap Int -> Map.IntMap Int
    dp n tagMap
      | n > target = tagMap
      | otherwise  = dp' n tagMap 0
    dp' :: Int -> Map.IntMap Int -> Int -> Map.IntMap Int
    dp' n tagMap x
      | (x + n) > target = tagMap
      | x == 0  = ins
      | oldcoins == 0 = dp' n tagMap  (x+1)
      | oldcoins + 1 < newcoins = ins
      | newcoins == 0 = ins
      | otherwise    = dp' n tagMap (x+1)
      where
        newcoins = tagMap Map.! (n+x)
        oldcoins :: Int
        oldcoins = tagMap Map.! x
        ins :: Map.IntMap Int
        ins = (dp' n (Map.insert (x+n) (oldcoins + 1) tagMap) (x+1))