big_w = gets.to_i num = gets.to_i n_w = gets.to_s n_w2 = n_w.split(" ") n_w2.map!(&:to_i) i = 0 ans = 0 n_w2.sort.each_with_index do |a, index| if big_w >= n_w2.inject(:+) ans = n_w2.length elsif i + a == big_w ans = index + 1 elsif i + a > big_w ans = index break else i += a end end puts ans