K = int(eval(input()))



def cal():

    count = 9

    d = [[1,2,3,4,5,6,7,8,9]]

    for i in range(10**9):

        d_ = []

        for j in range(len(d[i])):

            a = str(d[i][j])

            if a[-1]=="0":

                for k in [0, 1]:

                    d_.append(int(a)*10+k)

                    count += 1

                    if K == count:

                        print((d_[-1]))

                        return

            elif a[-1]=="9":

                for k in [8, 9]:

                    d_.append(int(a)*10+k)

                    count += 1

                    if K == count:

                        print((d_[-1]))

                        return 

            else:

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

                    d_.append(int(a)*10+int(a[-1])+k)

                    count += 1

                    if K == count:

                        print((d_[-1]))

                        return

        d.append(d_)

if K <= 9:

    print(K)

else:

    cal()
from collections import deque

k = int(eval(input()))

if k <= 9: print(k)

que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

count = 9

while count <= k:

    X = que.popleft()

    if X%10==0: check=[0, 1]

    elif X%10==9: check=[8, 9]

    else: check = [X%10-1, X%10, X%10+1]

    for i in check:

        que.append(X*10+i)

        count += 1

        if count == k:

            print((que[-1]))

            exit()
K = int(eval(input()))


def cal():
    count = 9
    d = [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
    for i in range(10**9):
        d_ = []
        for j in range(len(d[i])):
            a = str(d[i][j])
            if a[-1] == "0":
                for k in [0, 1]:
                    d_.append(int(a) * 10 + k)
                    count += 1
                    if K == count:
                        print((d_[-1]))
                        return
            elif a[-1] == "9":
                for k in [8, 9]:
                    d_.append(int(a) * 10 + k)
                    count += 1
                    if K == count:
                        print((d_[-1]))
                        return
            else:
                for k in [-1, 0, 1]:
                    d_.append(int(a) * 10 + int(a[-1]) + k)
                    count += 1
                    if K == count:
                        print((d_[-1]))
                        return
        d.append(d_)


if K <= 9:
    print(K)
else:
    cal()

from collections import deque

k = int(eval(input()))
if k <= 9:
    print(k)
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
count = 9
while count <= k:
    X = que.popleft()
    if X % 10 == 0:
        check = [0, 1]
    elif X % 10 == 9:
        check = [8, 9]
    else:
        check = [X % 10 - 1, X % 10, X % 10 + 1]
    for i in check:
        que.append(X * 10 + i)
        count += 1
        if count == k:
            print((que[-1]))
            exit()

-K = int(eval(input())) +from collections import deque - -def cal(): -    count = 9 -    d = [[1, 2, 3, 4, 5, 6, 7, 8, 9]] -    for i in range(10**9): -        d_ = [] -        for j in range(len(d[i])): -            a = str(d[i][j]) -            if a[-1] == "0": -                for k in [0, 1]: -                    d_.append(int(a) * 10 + k) -                    count += 1 -                    if K == count: -                        print((d_[-1])) -                        return -            elif a[-1] == "9": -                for k in [8, 9]: -                    d_.append(int(a) * 10 + k) -                    count += 1 -                    if K == count: -                        print((d_[-1])) -                        return -            else: -                for k in [-1, 0, 1]: -                    d_.append(int(a) * 10 + int(a[-1]) + k) -                    count += 1 -                    if K == count: -                        print((d_[-1])) -                        return -        d.append(d_) - - -if K <= 9: -    print(K) -else: -    cal() +k = int(eval(input())) +if k <= 9: +    print(k) +que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) +count = 9 +while count <= k: +    X = que.popleft() +    if X % 10 == 0: +        check = [0, 1] +    elif X % 10 == 9: +        check = [8, 9] +    else: +        check = [X % 10 - 1, X % 10, X % 10 + 1] +    for i in check: +        que.append(X * 10 + i) +        count += 1 +        if count == k: +            print((que[-1])) +            exit()