box = gets.to_i num = gets.to_i widths = gets.split(" ") widths.map!(&:to_i) widths.sort! sum = 0 count = 0 widths.each do |i| sum += i break if sum > box count += 1 end puts count