from collections import deque





K = int(eval(input()))



que = deque(["1","2","3","4","5","6","7","8","9"])

cnt = 0

while cnt < K:

    q = que.popleft()

    a = int(q[-1])

    q = int(q)

    cnt += 1 

    if a == 0:

        que.append(str(q*10+a))

        que.append(str(q*10+a+1))

    elif a == 9:

        que.append(str(q*10+a-1))

        que.append(str(q*10+a))

    else:

        que.append(str(q*10+a-1))

        que.append(str(q*10+a))

        que.append(str(q*10+a+1))

    ans = q



print(ans)
import sys

sys.setrecursionlimit(10**9)



k = int(eval(input()))

l = 10

A = [str(i+1) for i in range(9)]

B = ["0"] + A

ans = []

#print(l)



def dfs(num,l):

    if len(num) >= l:

        ans.append(int(num))

    else:

        ans.append(int(num))

        for i in B:

            if abs(int(num[-1])-int(i)) < 2:

                dfs(num + i,l)

if k <= 9:

    print(k)

else:

    for i in A:

        dfs(i,l)

    ans = sorted(ans)

    #print(ans)

    print((ans[k-1]))
from collections import deque

K = int(eval(input()))
que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
cnt = 0
while cnt < K:
    q = que.popleft()
    a = int(q[-1])
    q = int(q)
    cnt += 1
    if a == 0:
        que.append(str(q * 10 + a))
        que.append(str(q * 10 + a + 1))
    elif a == 9:
        que.append(str(q * 10 + a - 1))
        que.append(str(q * 10 + a))
    else:
        que.append(str(q * 10 + a - 1))
        que.append(str(q * 10 + a))
        que.append(str(q * 10 + a + 1))
    ans = q
print(ans)

import sys

sys.setrecursionlimit(10**9)
k = int(eval(input()))
l = 10
A = [str(i + 1) for i in range(9)]
B = ["0"] + A
ans = []
# print(l)
def dfs(num, l):
    if len(num) >= l:
        ans.append(int(num))
    else:
        ans.append(int(num))
        for i in B:
            if abs(int(num[-1]) - int(i)) < 2:
                dfs(num + i, l)


if k <= 9:
    print(k)
else:
    for i in A:
        dfs(i, l)
    ans = sorted(ans)
    # print(ans)
    print((ans[k - 1]))

-from collections import deque +import sys -K = int(eval(input())) -que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) -cnt = 0 -while cnt < K: -    q = que.popleft() -    a = int(q[-1]) -    q = int(q) -    cnt += 1 -    if a == 0: -        que.append(str(q * 10 + a)) -        que.append(str(q * 10 + a + 1)) -    elif a == 9: -        que.append(str(q * 10 + a - 1)) -        que.append(str(q * 10 + a)) +sys.setrecursionlimit(10**9) +k = int(eval(input())) +l = 10 +A = [str(i + 1) for i in range(9)] +B = ["0"] + A +ans = [] +# print(l) +def dfs(num, l): +    if len(num) >= l: +        ans.append(int(num)) -        que.append(str(q * 10 + a - 1)) -        que.append(str(q * 10 + a)) -        que.append(str(q * 10 + a + 1)) -    ans = q -print(ans) +        ans.append(int(num)) +        for i in B: +            if abs(int(num[-1]) - int(i)) < 2: +                dfs(num + i, l) + + +if k <= 9: +    print(k) +else: +    for i in A: +        dfs(i, l) +    ans = sorted(ans) +    # print(ans) +    print((ans[k - 1]))