K = int(eval(input()))



lunlun_number_list = []



def dfs(N):

    lunlun_number_list.append(N)

    if len(str(N)) > 10:

        return

    now_int = int(str(N)[-1])

    if now_int == 0:

        for i in range(2):

            dfs(N*10 + i)

    elif now_int == 9:

        for i in range(8, 10, 1):

            dfs(N*10 + i)

    else:

        for i in range(now_int-1, now_int+2, 1):

            dfs(N*10 + i)



for i in range(1, 10, 1):

    dfs(i)



lunlun_number_list.sort()

print((lunlun_number_list[K-1]))

import collections

K = int(eval(input()))



que = collections.deque()

for i in range(1, 10, 1):

    que.append(i)

cnt = 0

for i in range(K):

    x = que.popleft()

    cnt += 1

    if cnt == K:

        print(x)

        exit()

    if x%10 == 0:

        que.append(10*x+0)

        que.append(10*x+1)

    elif x%10 == 9:

        que.append(10*x+8)

        que.append(10*x+9)

    else:

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

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

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



K = int(eval(input()))
lunlun_number_list = []


def dfs(N):
    lunlun_number_list.append(N)
    if len(str(N)) > 10:
        return
    now_int = int(str(N)[-1])
    if now_int == 0:
        for i in range(2):
            dfs(N * 10 + i)
    elif now_int == 9:
        for i in range(8, 10, 1):
            dfs(N * 10 + i)
    else:
        for i in range(now_int - 1, now_int + 2, 1):
            dfs(N * 10 + i)


for i in range(1, 10, 1):
    dfs(i)
lunlun_number_list.sort()
print((lunlun_number_list[K - 1]))

import collections

K = int(eval(input()))
que = collections.deque()
for i in range(1, 10, 1):
    que.append(i)
cnt = 0
for i in range(K):
    x = que.popleft()
    cnt += 1
    if cnt == K:
        print(x)
        exit()
    if x % 10 == 0:
        que.append(10 * x + 0)
        que.append(10 * x + 1)
    elif x % 10 == 9:
        que.append(10 * x + 8)
        que.append(10 * x + 9)
    else:
        que.append(10 * x + (x % 10) - 1)
        que.append(10 * x + (x % 10) + 0)
        que.append(10 * x + (x % 10) + 1)

+import collections + -lunlun_number_list = [] - - -def dfs(N): -    lunlun_number_list.append(N) -    if len(str(N)) > 10: -        return -    now_int = int(str(N)[-1]) -    if now_int == 0: -        for i in range(2): -            dfs(N * 10 + i) -    elif now_int == 9: -        for i in range(8, 10, 1): -            dfs(N * 10 + i) +que = collections.deque() +for i in range(1, 10, 1): +    que.append(i) +cnt = 0 +for i in range(K): +    x = que.popleft() +    cnt += 1 +    if cnt == K: +        print(x) +        exit() +    if x % 10 == 0: +        que.append(10 * x + 0) +        que.append(10 * x + 1) +    elif x % 10 == 9: +        que.append(10 * x + 8) +        que.append(10 * x + 9) -        for i in range(now_int - 1, now_int + 2, 1): -            dfs(N * 10 + i) - - -for i in range(1, 10, 1): -    dfs(i) -lunlun_number_list.sort() -print((lunlun_number_list[K - 1])) +        que.append(10 * x + (x % 10) - 1) +        que.append(10 * x + (x % 10) + 0) +        que.append(10 * x + (x % 10) + 1)