import Control.Applicative import Data.List solve l ws = subtract 1 $ length $ unfoldr go (l,ws) where go (m,[]) = Just (m, (-1,[0])) go (m,x:xs) | m >= 0 = Just (m, (m-x,xs)) | otherwise = Nothing main = do l <- (read :: String -> Int) <$> getLine n <- getLine ws <- fmap (read :: String -> Int) . words <$> getLine print $ solve l $ sort ws