open System let rec solve (i : int) (sum : int) (l : int) (n : int) (ws : int array) = if i = n then n else let s = sum + ws.[i] if s > l then l else solve (i + 1) (sum + ws.[i]) l n ws [] let main _ = let l = stdin.ReadLine() |> int let n = stdin.ReadLine() |> int let ws = stdin.ReadLine().Split(' ') |> Array.map int |> Array.sort printfn "%d" (solve 0 0 l n ws) 0 // return an integer exit code