L = gets.to_i N = gets.to_i W = gets.split.map(&:to_i).sort! sum = 0 count = 0 (0..W.size).each do |i| sum += W[i] if sum >= L puts count exit end count += 1 end