n=int(eval(input()))

import queue

q=queue.Queue()

for i in range(1,10):

    q.put(i)

while n!=1:

    x=q.get();k=x%10

    for j in [10*x+i for i in range(max(0,k-1),min(10,k+2))] :

        q.put(j)

    n-=1

print((q.get()))
n=int(eval(input()))

import queue

q=queue.Queue()

for i in range(1,10):

    q.put(i)

while n!=1:

    x=q.get();k=x%10

    for i in range(max(0,k-1),min(10,k+2)) :

        q.put(10*x+i)

    n-=1

print((q.get()))
n = int(eval(input()))
import queue

q = queue.Queue()
for i in range(1, 10):
    q.put(i)
while n != 1:
    x = q.get()
    k = x % 10
    for j in [10 * x + i for i in range(max(0, k - 1), min(10, k + 2))]:
        q.put(j)
    n -= 1
print((q.get()))

n = int(eval(input()))
import queue

q = queue.Queue()
for i in range(1, 10):
    q.put(i)
while n != 1:
    x = q.get()
    k = x % 10
    for i in range(max(0, k - 1), min(10, k + 2)):
        q.put(10 * x + i)
    n -= 1
print((q.get()))

-    for j in [10 * x + i for i in range(max(0, k - 1), min(10, k + 2))]: -        q.put(j) +    for i in range(max(0, k - 1), min(10, k + 2)): +        q.put(10 * x + i)