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 else let s=sum+w.[i] if s>l then i else f (i+1) (sum+w.[i]) f 0 0 |> stdout.WriteLine