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 $ minCoins m n coins

minCoins :: Int -> Int -> Array Int Int -> Int
minCoins i j carr
  | j < 0 = (maxBound - 1)
  | j == 0 = 0
  | i == 1 = j
  | otherwise = min (minCoins (i-1) j carr ) (minCoins i (j- carr!i) carr + 1)