import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



k = int(readline())

q = [(i + 1) for i in range(9)]

if k < 10:

    print(k)

    exit()

cnt = 9

while q:

    x = q.pop(0)

    y = int(str(x)[-1])

    if y != 0:

        cnt += 1

        if cnt == k:

            print((10 * x + y - 1))

            exit()

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

    cnt += 1

    if cnt == k:

        print((10 * x + y))

        exit()

    q.append(10 * x + y)

    if y != 9:

        cnt += 1

        if cnt == k:

            print((10 * x + y + 1))

            exit()

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

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

sys.setrecursionlimit(10 ** 7)



from collections import deque



k = int(readline())

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

for i in range(k - 1):

    x = q.popleft()

    y = int(x[-1])

    if y != 0:

        q.append(x + str(y - 1))

    q.append(x + x[-1])

    if y != 9:

        q.append(x + str(y + 1))

print((q[0]))

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
    exit()
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print((10 * x + y - 1))
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print((10 * x + y))
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print((10 * x + y + 1))
            exit()
        q.append(10 * x + y + 1)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from collections import deque

k = int(readline())
q = deque(list(map(str, list(range(1, 10)))))
for i in range(k - 1):
    x = q.popleft()
    y = int(x[-1])
    if y != 0:
        q.append(x + str(y - 1))
    q.append(x + x[-1])
    if y != 9:
        q.append(x + str(y + 1))
print((q[0]))

+from collections import deque + -q = [(i + 1) for i in range(9)] -if k < 10: -    print(k) -    exit() -cnt = 9 -while q: -    x = q.pop(0) -    y = int(str(x)[-1]) +q = deque(list(map(str, list(range(1, 10))))) +for i in range(k - 1): +    x = q.popleft() +    y = int(x[-1]) -        cnt += 1 -        if cnt == k: -            print((10 * x + y - 1)) -            exit() -        q.append(10 * x + y - 1) -    cnt += 1 -    if cnt == k: -        print((10 * x + y)) -        exit() -    q.append(10 * x + y) +        q.append(x + str(y - 1)) +    q.append(x + x[-1]) -        cnt += 1 -        if cnt == k: -            print((10 * x + y + 1)) -            exit() -        q.append(10 * x + y + 1) +        q.append(x + str(y + 1)) +print((q[0]))