total = gets.to_i gets ws = gets.split.map(&:to_i) result = 0 ws.sort.each do |w| if total < w break end total -= w result += 1 end puts result