width = gets.chomp.to_i block_count = gets.chomp.to_i blocks = gets.chomp.split(" ").map(&:to_i).sort! current_width = 0 blocks.each_with_index do |b, i| current_width += b if current_width > width puts i break elsif block_count == i+1 puts i + 1 end end