import Control.Monad.Reader
import Data.Array.IArray

main = do
    [n,m] <- fmap (map read.words) getLine
    cs <- fmap (map read.words) getLine
    let coins = array (1,m) $ zip [1..] cs
    print $ runReader (minCoinsR m n) coins

minCoinsR :: Int -> Int -> Reader (Array Int Int) Int
minCoinsR i j
  | j < 0 = return (maxBound - 1)
  | j == 0 = return 0
  | i == 1 = return j
  | otherwise = do
       arr <- ask
       l <- minCoinsR (i-1) j
       r <- minCoinsR i (j-arr!i)
       return $ min l (r+1)