let l = stdin.ReadLine() |> int let n = stdin.ReadLine() |> int let w = stdin.ReadLine().Split() |> Array.map int |> Array.sort let rec f i sum = if i=n then n elif sum>l then (i-1) else f (i+1) (sum+w.[i]) f 0 0 |> stdout.WriteLine