import Control.Applicative ((<$>))
import Data.List (sort)
import qualified Data.Vector as V

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 = (V.map (f.xdi) is V.!) . idx
        is = V.enumFromN 0 (1+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