box_width = gets.to_i block_num = gets.to_i array_box_w = gets.split.map(&:to_i).sort result = 0 sum_width = 0 array_box_w.each do |width| sum_width += width break if box_width < sum_width result += 1 end puts result