# Problem D - Lunlun Number



# input

K = int(eval(input()))



# initialization

num_queue = []

k = 1



# count

while True:

    if k>=1 and k<=9: # 1桁の場合

        num_queue.append(k)

        k += 1

    else: # 2桁以降の場合

        min_num = str(num_queue.pop(0))

        keta_1 = int(min_num[-1])

        if keta_1==0:

            for i in range(2):

                tmp = int(min_num + str(i))

                num_queue.append(tmp)

                k += 1

                if k>K:

                    break

        elif keta_1==9:

            for i in range(keta_1-1, keta_1+1):

                tmp = int(min_num + str(i))

                num_queue.append(tmp)

                k += 1

                if k>K:

                    break

        else:

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

                tmp = int(min_num + str(i))

                num_queue.append(tmp)

                k += 1

                if k>K:

                    break

    if k>K:

        break



# output

print((num_queue[-1]))

# Problem D - Lunlun Number



from collections import deque



# input

K = int(eval(input()))



# initialization

num_queue = deque()

k = 1



# count

while True:

    if k>=1 and k<=9:

        num_queue.append(k)

        k += 1

    else:

        num = str(num_queue.popleft())

        num_str = int(num[-1])

        if num_str==0:

            for i in range(2):

                tmp = str(i)

                num_queue.append(int(num + tmp))

                k += 1

                if k-1==K:

                    break

        elif num_str==9:

            for i in range(8,10):

                tmp = str(i)

                num_queue.append(int(num + tmp))

                k += 1

                if k-1==K:

                    break

        else:

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

                tmp = str(i)

                num_queue.append(int(num + tmp))

                k += 1

                if k-1==K:

                    break



    if k-1==K:

        break



# output

print((num_queue[-1]))

# Problem D - Lunlun Number
# input
K = int(eval(input()))
# initialization
num_queue = []
k = 1
# count
while True:
    if k >= 1 and k <= 9:  # 1桁の場合
        num_queue.append(k)
        k += 1
    else:  # 2桁以降の場合
        min_num = str(num_queue.pop(0))
        keta_1 = int(min_num[-1])
        if keta_1 == 0:
            for i in range(2):
                tmp = int(min_num + str(i))
                num_queue.append(tmp)
                k += 1
                if k > K:
                    break
        elif keta_1 == 9:
            for i in range(keta_1 - 1, keta_1 + 1):
                tmp = int(min_num + str(i))
                num_queue.append(tmp)
                k += 1
                if k > K:
                    break
        else:
            for i in range(keta_1 - 1, keta_1 + 2):
                tmp = int(min_num + str(i))
                num_queue.append(tmp)
                k += 1
                if k > K:
                    break
    if k > K:
        break
# output
print((num_queue[-1]))

# Problem D - Lunlun Number
from collections import deque

# input
K = int(eval(input()))
# initialization
num_queue = deque()
k = 1
# count
while True:
    if k >= 1 and k <= 9:
        num_queue.append(k)
        k += 1
    else:
        num = str(num_queue.popleft())
        num_str = int(num[-1])
        if num_str == 0:
            for i in range(2):
                tmp = str(i)
                num_queue.append(int(num + tmp))
                k += 1
                if k - 1 == K:
                    break
        elif num_str == 9:
            for i in range(8, 10):
                tmp = str(i)
                num_queue.append(int(num + tmp))
                k += 1
                if k - 1 == K:
                    break
        else:
            for i in range(num_str - 1, num_str + 2):
                tmp = str(i)
                num_queue.append(int(num + tmp))
                k += 1
                if k - 1 == K:
                    break
    if k - 1 == K:
        break
# output
print((num_queue[-1]))

+from collections import deque + -num_queue = [] +num_queue = deque() -    if k >= 1 and k <= 9:  # 1桁の場合 +    if k >= 1 and k <= 9: -    else:  # 2桁以降の場合 -        min_num = str(num_queue.pop(0)) -        keta_1 = int(min_num[-1]) -        if keta_1 == 0: +    else: +        num = str(num_queue.popleft()) +        num_str = int(num[-1]) +        if num_str == 0: -                tmp = int(min_num + str(i)) -                num_queue.append(tmp) +                tmp = str(i) +                num_queue.append(int(num + tmp)) -                if k > K: +                if k - 1 == K: -        elif keta_1 == 9: -            for i in range(keta_1 - 1, keta_1 + 1): -                tmp = int(min_num + str(i)) -                num_queue.append(tmp) +        elif num_str == 9: +            for i in range(8, 10): +                tmp = str(i) +                num_queue.append(int(num + tmp)) -                if k > K: +                if k - 1 == K: -            for i in range(keta_1 - 1, keta_1 + 2): -                tmp = int(min_num + str(i)) -                num_queue.append(tmp) +            for i in range(num_str - 1, num_str + 2): +                tmp = str(i) +                num_queue.append(int(num + tmp)) -                if k > K: +                if k - 1 == K: -    if k > K: +    if k - 1 == K: