l = gets.not_nil!.to_i n = gets.not_nil!.to_i weights = [] of Int32 while weights.size < n weights.concat gets.not_nil!.split.map(&.to_i) end weights.sort! sum = 0 count = 0 weights.each do |w| sum += w break if sum > l count += 1 end puts count