import queue

K = int(eval(input()))

q = queue.Queue()

for i in range(1, 10):

    q.put(i)

for _ in range(K):

    x = q.get()

    d = x%10

    t = x*10

    if d != 0:

        q.put(t-1+d)

    q.put(t+d)

    if d != 9:

        q.put(t+1+d)

print(x)
# coding: utf-8

# d 現在の桁

# val 現在の値

# all 格納

def rec(d, val, all):

    # 格納

    all.append(val)

    # 10桁なら終了

    if d == 10:

        return

    # 再帰

    for i in range(-1, 2):

        add = val%10 + i

        if 0 <= add <= 9:

            rec(d+1, val*10+add, all)



# main

K = int(eval(input()))

all = []



# 1~9までを格納＆処理

for i in range(1, 10):

    rec(1, i, all)



all.sort()

print((all[K-1]))
import queue

K = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
for _ in range(K):
    x = q.get()
    d = x % 10
    t = x * 10
    if d != 0:
        q.put(t - 1 + d)
    q.put(t + d)
    if d != 9:
        q.put(t + 1 + d)
print(x)

# coding: utf-8
# d 現在の桁
# val 現在の値
# all 格納
def rec(d, val, all):
    # 格納
    all.append(val)
    # 10桁なら終了
    if d == 10:
        return
    # 再帰
    for i in range(-1, 2):
        add = val % 10 + i
        if 0 <= add <= 9:
            rec(d + 1, val * 10 + add, all)


# main
K = int(eval(input()))
all = []
# 1~9までを格納＆処理
for i in range(1, 10):
    rec(1, i, all)
all.sort()
print((all[K - 1]))

-import queue +# coding: utf-8 +# d 現在の桁 +# val 現在の値 +# all 格納 +def rec(d, val, all): +    # 格納 +    all.append(val) +    # 10桁なら終了 +    if d == 10: +        return +    # 再帰 +    for i in range(-1, 2): +        add = val % 10 + i +        if 0 <= add <= 9: +            rec(d + 1, val * 10 + add, all) + +# main -q = queue.Queue() +all = [] +# 1~9までを格納＆処理 -    q.put(i) -for _ in range(K): -    x = q.get() -    d = x % 10 -    t = x * 10 -    if d != 0: -        q.put(t - 1 + d) -    q.put(t + d) -    if d != 9: -        q.put(t + 1 + d) -print(x) +    rec(1, i, all) +all.sort() +print((all[K - 1]))