def gen_lunlun(digit, li):

    if len(li) == digit:

        lunluns.append(''.join(map(str, li)))

        return

    min_num = max(0, li[-1] - 1)

    max_num = min(9, li[-1] + 1)

    for i in range(min_num, max_num + 1):

        gen_lunlun(digit, li + [i])





k = int(eval(input()))



lunluns = []

for d in range(1, 11):

    for i in range(1, 10):

        gen_lunlun(d, [i])

print((lunluns[k - 1]))

from collections import deque





def nth_ll(k):

    if k < 10:

        return k

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

    cnt = 9

    while True:

        n = queue.popleft()

        for i in range(-1 if n % 10 != 0 else 0, 2 if n % 10 != 9 else 1):

            queue.append(10 * n + n % 10 + i)

            cnt += 1

            if cnt == k:

                return queue.pop()



print((nth_ll(int(eval(input())))))

def gen_lunlun(digit, li):
    if len(li) == digit:
        lunluns.append("".join(map(str, li)))
        return
    min_num = max(0, li[-1] - 1)
    max_num = min(9, li[-1] + 1)
    for i in range(min_num, max_num + 1):
        gen_lunlun(digit, li + [i])


k = int(eval(input()))
lunluns = []
for d in range(1, 11):
    for i in range(1, 10):
        gen_lunlun(d, [i])
print((lunluns[k - 1]))

from collections import deque


def nth_ll(k):
    if k < 10:
        return k
    queue = deque([i for i in range(1, 10)])
    cnt = 9
    while True:
        n = queue.popleft()
        for i in range(-1 if n % 10 != 0 else 0, 2 if n % 10 != 9 else 1):
            queue.append(10 * n + n % 10 + i)
            cnt += 1
            if cnt == k:
                return queue.pop()


print((nth_ll(int(eval(input())))))

-def gen_lunlun(digit, li): -    if len(li) == digit: -        lunluns.append("".join(map(str, li))) -        return -    min_num = max(0, li[-1] - 1) -    max_num = min(9, li[-1] + 1) -    for i in range(min_num, max_num + 1): -        gen_lunlun(digit, li + [i]) +from collections import deque -k = int(eval(input())) -lunluns = [] -for d in range(1, 11): -    for i in range(1, 10): -        gen_lunlun(d, [i]) -print((lunluns[k - 1])) +def nth_ll(k): +    if k < 10: +        return k +    queue = deque([i for i in range(1, 10)]) +    cnt = 9 +    while True: +        n = queue.popleft() +        for i in range(-1 if n % 10 != 0 else 0, 2 if n % 10 != 9 else 1): +            queue.append(10 * n + n % 10 + i) +            cnt += 1 +            if cnt == k: +                return queue.pop() + + +print((nth_ll(int(eval(input())))))