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
    where
        table = foldl build is [1..m-1]
        is = listArray (0,n) [0..n]
        build pre y = listArray (0,n) $ map f [0..n]
          where
              c = cs !! y
              f x | c > x = pre ! x
                  | otherwise = pre ! x `min` (1 + build pre y ! (x-c))