l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i) s = 0 ii = 0 w.sort.each do |i| s += i if s > l break end ii += 1 end puts ii