l = parse(Int,readline()) n = parse(Int,readline()) w = parse.(Int,readline() |> split) |> sort |> cumsum searchsortedlast(w,l) |> println