L = gets.to_i N = gets.to_i W = gets.split.map(&:to_i) widths = W.sort! ans = [] widths.each do |width| break if ans.sum >= L ans << width end puts ans.count - 1