def c9(k); 9 < k ? 9 : k end
def f0(k); k < 0 ? 0 : k end

k = gets.to_i

c = 0
(1..9).each do |i|
  c += 1
  if k == c
    puts i
  end
end

(1..9).each do |i|
  ((i-1)..c9(i+1)).each do |j|
    c += 1
    if k == c 
      puts i * 10 + j 
    end
  end
end

(1..9).each do |i|
  ((i-1)..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      c += 1
      if k == c
        puts i * 100 + j * 10 + x 
      end
    end
  end
end

(1..9).each do |i|
  ((i-1)..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        c += 1
        if k == c
          puts i * 1000 + j * 100 + x * 10 + l 
        end
      end
    end
  end
end

(1..9).each do |i|
  (i-1..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        (f0(l-1)..c9(l+1)).each do |m|
          c += 1
          if k == c
            puts i * 10000 + j * 1000 + x * 100 + l * 10  + m 
          end
        end
      end
    end
  end
end

(1..9).each do |i|
  (i-1..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        (f0(l-1)..c9(l+1)).each do |m|
          (f0(m-1)..c9(m+1)).each do |n|
            c += 1
            if k == c
              puts i * 100000 + j * 10000 + x * 1000 + l * 100  + m * 10 + n 
            end
          end
        end
      end
    end
  end
end

(1..9).each do |i|
  (i-1..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        (f0(l-1)..c9(l+1)).each do |m|
          (f0(m-1)..c9(m+1)).each do |n|
            (f0(n-1)..c9(n+1)).each do |o|
              c += 1
              if k == c
                puts i * 1000000 + j * 100000 + x * 10000 + l * 1000  + m * 100 + n * 10 + o
              end
            end
          end
        end
      end
    end
  end
end

(1..9).each do |i|
  (i-1..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        (f0(l-1)..c9(l+1)).each do |m|
          (f0(m-1)..c9(m+1)).each do |n|
            (f0(n-1)..c9(n+1)).each do |o|
              (f0(o-1)..c9(o+1)).each do |q|
                c += 1
                if k == c
                  puts i * 10000000 + j * 1000000 + x * 100000 + l * 10000  + m * 1000 + n * 100 + o * 10 + q
                end
              end
            end
          end
        end
      end
    end
  end
end

(1..9).each do |i|
  ((i-1)..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        (f0(l-1)..c9(l+1)).each do |m|
          (f0(m-1)..c9(m+1)).each do |n|
            (f0(n-1)..c9(n+1)).each do |o|
              (f0(o-1)..c9(o+1)).each do |q|
                (f0(q-1)..c9(q+1)).each do |r|
                  c += 1
                  if k == c
                    puts i * 100000000 + j * 10000000 + x * 1000000 + l * 100000  + m * 10000 + n * 1000 + o * 100 + q * 10 + r
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

(1..9).each do |i|
  (i-1..c9(i+1)).each do |j|
    (f0(j-1)..c9(j+1)).each do |x|
      (f0(x-1)..c9(x+1)).each do |l|
        (f0(l-1)..c9(l+1)).each do |m|
          (f0(m-1)..c9(m+1)).each do |n|
            (f0(n-1)..c9(n+1)).each do |o|
              (f0(o-1)..c9(o+1)).each do |q|
                (f0(q-1)..c9(q+1)).each do |r|
                  (f0(r-1)..c9(r+1)).each do |s|
                    c += 1
                    if k == c
                      puts i * 1000000000 + j * 100000000 + x * 10000000 + l * 1000000  + m * 100000 + n * 10000 + o * 1000 + q * 100 + r * 10 + s
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Measured memory_bytes: 1916