from queue import Queue



k = int(eval(input()))



q = Queue()

for i in range(1, 10):

    q.put(i)



for _ in range(k):

    x = q.get()

    if x % 10 != 0:

        q.put(x*10 + x%10 - 1)

    q.put(x*10 + x%10)

    if x % 10 != 9:

        q.put(x*10 + x%10 + 1)



print(x)

from collections import deque



k = int(eval(input()))



q = deque(list(range(1, 10)))

for _ in range(k):

    x = q.popleft()

    if x % 10 != 0:

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

    q.append(x*10 + x%10)

    if x % 10 != 9:

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



print(x)
from queue import Queue

k = int(eval(input()))
q = Queue()
for i in range(1, 10):
    q.put(i)
for _ in range(k):
    x = q.get()
    if x % 10 != 0:
        q.put(x * 10 + x % 10 - 1)
    q.put(x * 10 + x % 10)
    if x % 10 != 9:
        q.put(x * 10 + x % 10 + 1)
print(x)

from collections import deque

k = int(eval(input()))
q = deque(list(range(1, 10)))
for _ in range(k):
    x = q.popleft()
    if x % 10 != 0:
        q.append(x * 10 + x % 10 - 1)
    q.append(x * 10 + x % 10)
    if x % 10 != 9:
        q.append(x * 10 + x % 10 + 1)
print(x)

-from queue import Queue +from collections import deque -q = Queue() -for i in range(1, 10): -    q.put(i) +q = deque(list(range(1, 10))) -    x = q.get() +    x = q.popleft() -        q.put(x * 10 + x % 10 - 1) -    q.put(x * 10 + x % 10) +        q.append(x * 10 + x % 10 - 1) +    q.append(x * 10 + x % 10) -        q.put(x * 10 + x % 10 + 1) +        q.append(x * 10 + x % 10 + 1)