import Control.Applicative ((<$>))
import Data.Array (listArray, (!))
import Data.List (sort)

main :: IO ()
main = do
    [n,m] <- getInts
    cs <- getInts
    print $ solve n m $ sort cs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: Int -> Int -> [Int] -> Int
solve n m cs = table (n,m-1)
    where
        idx (x,y) = x + y*(n+1)
        xdi i = (i`mod`(n+1), i`div`(n+1))
        table = (listArray (0,idx (n,m-1)) ls !) . idx
        ls = map (f.xdi $!) [0..idx (n,m-1)]
        f (x,0) = x
        f (x,y) = if c > x then table (x,y-1) else table (x,y-1) `min` (table (x-c,y) + 1)
            where c = cs !! y