l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i).sort sum = 0 w.each_with_index do |w, idx| sum += w if l <= sum puts idx return end end