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