# -*- coding: utf-8 -*-

# D - Lunlun Number

# 標準入力の取得

K = int(eval(input()))



# 求解

def get_lunlun_number_list(ln_list:list) -> list:

    lunlun_number_list = []

    for ln in ln_list:

        one_place_value = ln % 10

        lunlun_number_list.append(int(str(ln) + str(one_place_value)))

        if one_place_value != 0:

            lunlun_number_list.append(int(str(ln) + str(one_place_value-1)))

        if one_place_value != 9:

            lunlun_number_list.append(int(str(ln) + str(one_place_value+1)))



    return lunlun_number_list



lunlun_number_list = []



lunlun_number_list1 = list(range(1, 10))

lunlun_number_list.extend(lunlun_number_list1)

lunlun_number_list2 = get_lunlun_number_list(lunlun_number_list1)

lunlun_number_list.extend(lunlun_number_list2)

lunlun_number_list3 = get_lunlun_number_list(lunlun_number_list2)

lunlun_number_list.extend(lunlun_number_list3)

lunlun_number_list4 = get_lunlun_number_list(lunlun_number_list3)

lunlun_number_list.extend(lunlun_number_list4)

lunlun_number_list5 = get_lunlun_number_list(lunlun_number_list4)

lunlun_number_list.extend(lunlun_number_list5)

lunlun_number_list6 = get_lunlun_number_list(lunlun_number_list5)

lunlun_number_list.extend(lunlun_number_list6)

lunlun_number_list7 = get_lunlun_number_list(lunlun_number_list6)

lunlun_number_list.extend(lunlun_number_list7)

lunlun_number_list8 = get_lunlun_number_list(lunlun_number_list7)

lunlun_number_list.extend(lunlun_number_list8)

lunlun_number_list9 = get_lunlun_number_list(lunlun_number_list8)

lunlun_number_list.extend(lunlun_number_list9)

lunlun_number_list10 = get_lunlun_number_list(lunlun_number_list9)

lunlun_number_list.extend(lunlun_number_list10)



lunlun_number_list = sorted(lunlun_number_list)



# 結果出力

print((lunlun_number_list[K-1]))
# -*- coding: utf-8 -*-

# D - Lunlun Number

# モジュールのインポート

from collections import deque



# 標準入力の取得

K = int(eval(input()))



# 求解処理

# 空のQueueを一つ用意し、1, 2, ・・・, 9を順にEnqueue

que = deque(list(range(1, 10)))

lunlun_number = 0

for k in range(K):

    # Queueに対して、Dequeueを行う

    x = que.popleft()

    # x mod 10 ≠ 0なら、10x + (x mod 10) - 1をEnqueue

    if x % 10 != 0:

        que.append(10*x + (x%10) - 1)

    # 10x + (x mod 10)をEnqueue

    que.append(10*x + (x%10))

    # x mod 10 ≠ 9なら、10x + (x mod 10) + 1をEnqueue

    if x % 10 != 9:

        que.append(10*x + (x%10) + 1)



    # 上の操作をK回実施したときの値がLunlun Number

    lunlun_number = x



print(lunlun_number)
# -*- coding: utf-8 -*-
# D - Lunlun Number
# 標準入力の取得
K = int(eval(input()))
# 求解
def get_lunlun_number_list(ln_list: list) -> list:
    lunlun_number_list = []
    for ln in ln_list:
        one_place_value = ln % 10
        lunlun_number_list.append(int(str(ln) + str(one_place_value)))
        if one_place_value != 0:
            lunlun_number_list.append(int(str(ln) + str(one_place_value - 1)))
        if one_place_value != 9:
            lunlun_number_list.append(int(str(ln) + str(one_place_value + 1)))
    return lunlun_number_list


lunlun_number_list = []
lunlun_number_list1 = list(range(1, 10))
lunlun_number_list.extend(lunlun_number_list1)
lunlun_number_list2 = get_lunlun_number_list(lunlun_number_list1)
lunlun_number_list.extend(lunlun_number_list2)
lunlun_number_list3 = get_lunlun_number_list(lunlun_number_list2)
lunlun_number_list.extend(lunlun_number_list3)
lunlun_number_list4 = get_lunlun_number_list(lunlun_number_list3)
lunlun_number_list.extend(lunlun_number_list4)
lunlun_number_list5 = get_lunlun_number_list(lunlun_number_list4)
lunlun_number_list.extend(lunlun_number_list5)
lunlun_number_list6 = get_lunlun_number_list(lunlun_number_list5)
lunlun_number_list.extend(lunlun_number_list6)
lunlun_number_list7 = get_lunlun_number_list(lunlun_number_list6)
lunlun_number_list.extend(lunlun_number_list7)
lunlun_number_list8 = get_lunlun_number_list(lunlun_number_list7)
lunlun_number_list.extend(lunlun_number_list8)
lunlun_number_list9 = get_lunlun_number_list(lunlun_number_list8)
lunlun_number_list.extend(lunlun_number_list9)
lunlun_number_list10 = get_lunlun_number_list(lunlun_number_list9)
lunlun_number_list.extend(lunlun_number_list10)
lunlun_number_list = sorted(lunlun_number_list)
# 結果出力
print((lunlun_number_list[K - 1]))

# -*- coding: utf-8 -*-
# D - Lunlun Number
# モジュールのインポート
from collections import deque

# 標準入力の取得
K = int(eval(input()))
# 求解処理
# 空のQueueを一つ用意し、1, 2, ・・・, 9を順にEnqueue
que = deque(list(range(1, 10)))
lunlun_number = 0
for k in range(K):
    # Queueに対して、Dequeueを行う
    x = que.popleft()
    # x mod 10 ≠ 0なら、10x + (x mod 10) - 1をEnqueue
    if x % 10 != 0:
        que.append(10 * x + (x % 10) - 1)
    # 10x + (x mod 10)をEnqueue
    que.append(10 * x + (x % 10))
    # x mod 10 ≠ 9なら、10x + (x mod 10) + 1をEnqueue
    if x % 10 != 9:
        que.append(10 * x + (x % 10) + 1)
    # 上の操作をK回実施したときの値がLunlun Number
    lunlun_number = x
print(lunlun_number)

+# モジュールのインポート +from collections import deque + -# 求解 -def get_lunlun_number_list(ln_list: list) -> list: -    lunlun_number_list = [] -    for ln in ln_list: -        one_place_value = ln % 10 -        lunlun_number_list.append(int(str(ln) + str(one_place_value))) -        if one_place_value != 0: -            lunlun_number_list.append(int(str(ln) + str(one_place_value - 1))) -        if one_place_value != 9: -            lunlun_number_list.append(int(str(ln) + str(one_place_value + 1))) -    return lunlun_number_list - - -lunlun_number_list = [] -lunlun_number_list1 = list(range(1, 10)) -lunlun_number_list.extend(lunlun_number_list1) -lunlun_number_list2 = get_lunlun_number_list(lunlun_number_list1) -lunlun_number_list.extend(lunlun_number_list2) -lunlun_number_list3 = get_lunlun_number_list(lunlun_number_list2) -lunlun_number_list.extend(lunlun_number_list3) -lunlun_number_list4 = get_lunlun_number_list(lunlun_number_list3) -lunlun_number_list.extend(lunlun_number_list4) -lunlun_number_list5 = get_lunlun_number_list(lunlun_number_list4) -lunlun_number_list.extend(lunlun_number_list5) -lunlun_number_list6 = get_lunlun_number_list(lunlun_number_list5) -lunlun_number_list.extend(lunlun_number_list6) -lunlun_number_list7 = get_lunlun_number_list(lunlun_number_list6) -lunlun_number_list.extend(lunlun_number_list7) -lunlun_number_list8 = get_lunlun_number_list(lunlun_number_list7) -lunlun_number_list.extend(lunlun_number_list8) -lunlun_number_list9 = get_lunlun_number_list(lunlun_number_list8) -lunlun_number_list.extend(lunlun_number_list9) -lunlun_number_list10 = get_lunlun_number_list(lunlun_number_list9) -lunlun_number_list.extend(lunlun_number_list10) -lunlun_number_list = sorted(lunlun_number_list) -# 結果出力 -print((lunlun_number_list[K - 1])) +# 求解処理 +# 空のQueueを一つ用意し、1, 2, ・・・, 9を順にEnqueue +que = deque(list(range(1, 10))) +lunlun_number = 0 +for k in range(K): +    # Queueに対して、Dequeueを行う +    x = que.popleft() +    # x mod 10 ≠ 0なら、10x + (x mod 10) - 1をEnqueue +    if x % 10 != 0: +        que.append(10 * x + (x % 10) - 1) +    # 10x + (x mod 10)をEnqueue +    que.append(10 * x + (x % 10)) +    # x mod 10 ≠ 9なら、10x + (x mod 10) + 1をEnqueue +    if x % 10 != 9: +        que.append(10 * x + (x % 10) + 1) +    # 上の操作をK回実施したときの値がLunlun Number +    lunlun_number = x +print(lunlun_number)