K = int(eval(input()))

N = 10



S = [[] for _ in range(N + 1)]

for i in range(1, 10):

    S[1].append(i)



if K < 10:

    print((S[1][K - 1]))

    exit()



cnt = 9

for i in range(2, N + 1):

    for j in S[i - 1]:

        k = j % 10

        if 1 <= k <= 8:

            T = [-1, 0, 1]

        elif k == 0:

            T = [0, 1]

        else:

            T = [-1, 0]

        for t in T:

            S[i].append(j * 10 + (k + t))

            cnt += 1

            if cnt == K:

                print((S[i][-1]))

                exit()

from collections import deque





K = int(eval(input()))

q = deque()

for i in range(1, 10):

    q.append(i)



while K > 0:

    p = q.popleft()

    K -= 1

    r = p % 10

    if r != 0:

        q.append(10 * p + r - 1)

    q.append(10 * p + r)

    if r != 9:

        q.append(10 * p + r + 1)



print(p)

K = int(eval(input()))
N = 10
S = [[] for _ in range(N + 1)]
for i in range(1, 10):
    S[1].append(i)
if K < 10:
    print((S[1][K - 1]))
    exit()
cnt = 9
for i in range(2, N + 1):
    for j in S[i - 1]:
        k = j % 10
        if 1 <= k <= 8:
            T = [-1, 0, 1]
        elif k == 0:
            T = [0, 1]
        else:
            T = [-1, 0]
        for t in T:
            S[i].append(j * 10 + (k + t))
            cnt += 1
            if cnt == K:
                print((S[i][-1]))
                exit()

from collections import deque

K = int(eval(input()))
q = deque()
for i in range(1, 10):
    q.append(i)
while K > 0:
    p = q.popleft()
    K -= 1
    r = p % 10
    if r != 0:
        q.append(10 * p + r - 1)
    q.append(10 * p + r)
    if r != 9:
        q.append(10 * p + r + 1)
print(p)

+from collections import deque + -N = 10 -S = [[] for _ in range(N + 1)] +q = deque() -    S[1].append(i) -if K < 10: -    print((S[1][K - 1])) -    exit() -cnt = 9 -for i in range(2, N + 1): -    for j in S[i - 1]: -        k = j % 10 -        if 1 <= k <= 8: -            T = [-1, 0, 1] -        elif k == 0: -            T = [0, 1] -        else: -            T = [-1, 0] -        for t in T: -            S[i].append(j * 10 + (k + t)) -            cnt += 1 -            if cnt == K: -                print((S[i][-1])) -                exit() +    q.append(i) +while K > 0: +    p = q.popleft() +    K -= 1 +    r = p % 10 +    if r != 0: +        q.append(10 * p + r - 1) +    q.append(10 * p + r) +    if r != 9: +        q.append(10 * p + r + 1) +print(p)