L = gets.to_i N = gets.to_i W = gets.split.map(& :to_i).sort box = 0 ans = 0 W.each do |i| if box + i <= L box += i ans += 1 end end puts ans