
main = do
    str1 <- getLine
    let price:_ = map read $ split ' ' str1
    str2 <- getLine
    let coins = qsort $ map read $ split ' ' str2
    let selectedCoins = choiseCoin coins price
    putStrLn $ show $ length selectedCoins
    
putWithSpace :: Show a => [a] -> IO()
putWithSpace (x:[]) = putStrLn $ show x 
putWithSpace (x:xs) = putStr (show x ++ " ") >> putWithSpace xs

choiseCoin :: [Int] -> Int -> [Int]
choiseCoin cs p = case choiseOneCoin cs p of
                    Nothing -> []
                    Just c -> c : choiseCoin cs (p - c)

choiseOneCoin :: [Int] -> Int -> Maybe(Int)
choiseOneCoin [] _ = Nothing
choiseOneCoin _ 0 = Nothing
choiseOneCoin (c:cs) p
    | c <= p    = Just c
    | otherwise = choiseOneCoin cs p

split d = _split d []
_split d cs "" = cs
_split d cs s = _split d (cs ++ [token d s]) (drop (length(token d s) + 1) s)
 
token d = _token d ""
_token d t "" = t
_token d t (x:xs) = if (x == d) then t else _token d (t ++ [x]) xs

getInt :: IO (Int)
getInt = do
    str <- getLine
    return $ read str
    
qsort []     = []
qsort (p:xs) = qsort gteq ++ [p] ++ qsort lt
                 where
                   lt   = [x | x <- xs, x < p]
                   gteq = [x | x <- xs, x >= p]
