from queue import Queue

k = int(eval(input()))

q = Queue()

Lunlun = []

for i in range(1, 10):

    q.put(i)

while True:

    if len(Lunlun) >= 10**5:

        break

    now = q.get()

    Lunlun.append(now)

    for i in range(-1, 2):

        if (now % 10) + i < 0 or 9 < (now % 10) + i:

            continue

        q.put(now*10 + (now % 10) + i)



print((Lunlun[k-1]))
import collections

# from queue import Queue

k = int(eval(input()))

q = collections.deque()

Lunlun = []

for i in range(1, 10):

    q.append(i)

while True:

    if len(Lunlun) >= 10**5:

        break

    now = q.popleft()

    Lunlun.append(now)

    for i in range(-1, 2):

        if (now % 10) + i < 0 or 9 < (now % 10) + i:

            continue

        q.append(now*10 + (now % 10) + i)



print((Lunlun[k-1]))

from queue import Queue

k = int(eval(input()))
q = Queue()
Lunlun = []
for i in range(1, 10):
    q.put(i)
while True:
    if len(Lunlun) >= 10**5:
        break
    now = q.get()
    Lunlun.append(now)
    for i in range(-1, 2):
        if (now % 10) + i < 0 or 9 < (now % 10) + i:
            continue
        q.put(now * 10 + (now % 10) + i)
print((Lunlun[k - 1]))

import collections

# from queue import Queue
k = int(eval(input()))
q = collections.deque()
Lunlun = []
for i in range(1, 10):
    q.append(i)
while True:
    if len(Lunlun) >= 10**5:
        break
    now = q.popleft()
    Lunlun.append(now)
    for i in range(-1, 2):
        if (now % 10) + i < 0 or 9 < (now % 10) + i:
            continue
        q.append(now * 10 + (now % 10) + i)
print((Lunlun[k - 1]))

-from queue import Queue +import collections +# from queue import Queue -q = Queue() +q = collections.deque() -    q.put(i) +    q.append(i) -    now = q.get() +    now = q.popleft() -        q.put(now * 10 + (now % 10) + i) +        q.append(now * 10 + (now % 10) + i)