L = gets.to_i N = gets.to_i W = gets.split.map(&:to_i) widths = W.sort! ans = widths N.times do if ans.sum <= L break else ans.pop end end puts ans.count