lw = gets.to_i n = gets.to_i w = gets.split(" ").map(&:to_i).sort sum = 0 (0..n-1).each do |i| tmp = sum + w[i] if tmp < lw then sum = tmp else puts i break end end