let solve m c_lst = let rec solve' rest lst result = match lst with | [] -> result | x::xs -> if rest < x then result else solve' (rest - x) xs (result + 1) in solve' m c_lst 0 let () = let m = read_line () |> (fun l -> Scanf.sscanf l "%d %d" (fun _ m -> m)) and c_lst = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string |> List.sort compare in solve m c_lst |> string_of_int |> print_endline