import copy

K = int(eval(input()))

ans, nex = [i for i in range(1, 10)], [i for i in range(1, 10)]

for i in range(10):

    pre, nex = copy.deepcopy(nex), []

    for p in pre:

        if p % 10 != 0:

            ans.append(p * 10 + p % 10 - 1)

            nex.append(p * 10 + p % 10 - 1)

        ans.append(p * 10 + p % 10)

        nex.append(p * 10 + p % 10)

        if p % 10 != 9:

            ans.append(p * 10 + p % 10 + 1)

            nex.append(p * 10 + p % 10 + 1)



ans.sort()

print((ans[K - 1]))

from collections import deque

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



K = int(eval(input()))

for _ in range(K - 1):

    i = d.pop()

    if i % 10 != 0:

        d.appendleft(i * 10 + i % 10 - 1)

    d.appendleft(i * 10 + i % 10)

    if i % 10 != 9:

        d.appendleft(i * 10 + i % 10 + 1)

print((d.pop()))

import copy

K = int(eval(input()))
ans, nex = [i for i in range(1, 10)], [i for i in range(1, 10)]
for i in range(10):
    pre, nex = copy.deepcopy(nex), []
    for p in pre:
        if p % 10 != 0:
            ans.append(p * 10 + p % 10 - 1)
            nex.append(p * 10 + p % 10 - 1)
        ans.append(p * 10 + p % 10)
        nex.append(p * 10 + p % 10)
        if p % 10 != 9:
            ans.append(p * 10 + p % 10 + 1)
            nex.append(p * 10 + p % 10 + 1)
ans.sort()
print((ans[K - 1]))

from collections import deque

d = deque([9, 8, 7, 6, 5, 4, 3, 2, 1])
K = int(eval(input()))
for _ in range(K - 1):
    i = d.pop()
    if i % 10 != 0:
        d.appendleft(i * 10 + i % 10 - 1)
    d.appendleft(i * 10 + i % 10)
    if i % 10 != 9:
        d.appendleft(i * 10 + i % 10 + 1)
print((d.pop()))

-import copy +from collections import deque +d = deque([9, 8, 7, 6, 5, 4, 3, 2, 1]) -ans, nex = [i for i in range(1, 10)], [i for i in range(1, 10)] -for i in range(10): -    pre, nex = copy.deepcopy(nex), [] -    for p in pre: -        if p % 10 != 0: -            ans.append(p * 10 + p % 10 - 1) -            nex.append(p * 10 + p % 10 - 1) -        ans.append(p * 10 + p % 10) -        nex.append(p * 10 + p % 10) -        if p % 10 != 9: -            ans.append(p * 10 + p % 10 + 1) -            nex.append(p * 10 + p % 10 + 1) -ans.sort() -print((ans[K - 1])) +for _ in range(K - 1): +    i = d.pop() +    if i % 10 != 0: +        d.appendleft(i * 10 + i % 10 - 1) +    d.appendleft(i * 10 + i % 10) +    if i % 10 != 9: +        d.appendleft(i * 10 + i % 10 + 1) +print((d.pop()))