from collections import deque



k = int(eval(input()))

queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]

queue = deque(queue)

cnt = 0

while cnt < k:

    cnt += 1

    a = queue.popleft()

    hitoketa = a % 10

    kouho = [hitoketa - 1, hitoketa, hitoketa + 1]

    for b in kouho:

        if b >= 0 and b <= 9:

            queue.append(10 * a + b)

print(a)

from collections import deque



k = int(eval(input()))



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

LL = deque(LL)

for j in range(k):

    num = LL.popleft()

    amari = num % 10

    kouho = [amari - 1, amari, amari + 1]

    for nn in kouho:

        if nn >= 0 and nn < 10:

            LL.append(10 * num + nn)

print(num)

from collections import deque

k = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]
queue = deque(queue)
cnt = 0
while cnt < k:
    cnt += 1
    a = queue.popleft()
    hitoketa = a % 10
    kouho = [hitoketa - 1, hitoketa, hitoketa + 1]
    for b in kouho:
        if b >= 0 and b <= 9:
            queue.append(10 * a + b)
print(a)

from collections import deque

k = int(eval(input()))
LL = [i for i in range(1, 10)]
LL = deque(LL)
for j in range(k):
    num = LL.popleft()
    amari = num % 10
    kouho = [amari - 1, amari, amari + 1]
    for nn in kouho:
        if nn >= 0 and nn < 10:
            LL.append(10 * num + nn)
print(num)

-queue = [1, 2, 3, 4, 5, 6, 7, 8, 9] -queue = deque(queue) -cnt = 0 -while cnt < k: -    cnt += 1 -    a = queue.popleft() -    hitoketa = a % 10 -    kouho = [hitoketa - 1, hitoketa, hitoketa + 1] -    for b in kouho: -        if b >= 0 and b <= 9: -            queue.append(10 * a + b) -print(a) +LL = [i for i in range(1, 10)] +LL = deque(LL) +for j in range(k): +    num = LL.popleft() +    amari = num % 10 +    kouho = [amari - 1, amari, amari + 1] +    for nn in kouho: +        if nn >= 0 and nn < 10: +            LL.append(10 * num + nn) +print(num)