input = gets width = input.to_i input = gets number = input.to_i input = gets block = input.chomp.split(" ") block.map!(&:to_i) block.sort! sum = 0 number.times do |i| sum += block[i].to_i if sum > width then puts i break elsif i + 1 == number then puts i + 1 end end