# frozen_string_literal: true

def read
  gets.to_i
end

def solve(n)
  numbers = Enumerator.new { |y|
    n = 0
    loop {
      n = next_min n
      y << n
    }
  }
  numbers.take(n)
end

def candidates(n)
  digits = n.to_s.chars
  sz = digits.size
  (0...sz).map do |i|
    digits.take(i).concat(['9'].cycle.take(sz - i)).join('').to_i
  end
end

def next_min(n)
  s = -> i { i/i.to_s.chars.map(&:to_i).reduce(:+) }
  ([n.succ] + candidates(n.succ)).min_by {|i| s.(i)}
end

puts solve(read)
# puts [
#   solve(10) == [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 19]
# ].all?
