from collections import deque

k = int(eval(input()))

cnt = 0



q = deque()

for i in range(1, 10):

    q.append((str(i), i))

    cnt += 1

    if cnt == k:

        print((str(i)))

        exit()



while q:

    lun, num = q.popleft()



    for i in range(num - 1, num + 2):

        if i < 0 or i >9:continue

        temp = lun + str(i)

        q.append((temp, i))

        cnt += 1

        if cnt == k:

            print(temp)

            exit()
from collections import deque

def bfs(k):

    lunlun = []

    q = deque()

    count = 0

    for i in range(1, 10):

        lunlun.append(i)

        q.append(i)

        count += 1



    if count >= k:return lunlun[k - 1]



    while True:

        num = q.popleft()

        tail = num % 10

        for i in [-1, 0, 1]:

            temp = tail + i

            if temp == -1 or temp == 10:continue

            q.append(num * 10 + temp)

            lunlun.append(num * 10 + temp)

            count += 1

            if k == count:return lunlun[k - 1]



k = int(eval(input()))

print((bfs(k)))

from collections import deque

k = int(eval(input()))
cnt = 0
q = deque()
for i in range(1, 10):
    q.append((str(i), i))
    cnt += 1
    if cnt == k:
        print((str(i)))
        exit()
while q:
    lun, num = q.popleft()
    for i in range(num - 1, num + 2):
        if i < 0 or i > 9:
            continue
        temp = lun + str(i)
        q.append((temp, i))
        cnt += 1
        if cnt == k:
            print(temp)
            exit()

from collections import deque


def bfs(k):
    lunlun = []
    q = deque()
    count = 0
    for i in range(1, 10):
        lunlun.append(i)
        q.append(i)
        count += 1
    if count >= k:
        return lunlun[k - 1]
    while True:
        num = q.popleft()
        tail = num % 10
        for i in [-1, 0, 1]:
            temp = tail + i
            if temp == -1 or temp == 10:
                continue
            q.append(num * 10 + temp)
            lunlun.append(num * 10 + temp)
            count += 1
            if k == count:
                return lunlun[k - 1]


k = int(eval(input()))
print((bfs(k)))

+ +def bfs(k): +    lunlun = [] +    q = deque() +    count = 0 +    for i in range(1, 10): +        lunlun.append(i) +        q.append(i) +        count += 1 +    if count >= k: +        return lunlun[k - 1] +    while True: +        num = q.popleft() +        tail = num % 10 +        for i in [-1, 0, 1]: +            temp = tail + i +            if temp == -1 or temp == 10: +                continue +            q.append(num * 10 + temp) +            lunlun.append(num * 10 + temp) +            count += 1 +            if k == count: +                return lunlun[k - 1] + + -cnt = 0 -q = deque() -for i in range(1, 10): -    q.append((str(i), i)) -    cnt += 1 -    if cnt == k: -        print((str(i))) -        exit() -while q: -    lun, num = q.popleft() -    for i in range(num - 1, num + 2): -        if i < 0 or i > 9: -            continue -        temp = lun + str(i) -        q.append((temp, i)) -        cnt += 1 -        if cnt == k: -            print(temp) -            exit() +print((bfs(k)))