def d():

    k = int(eval(input()))



    val = 0

    hits = 0

    hit_tails = {}

    while hits < k:

        val += 1

        if len(str(val)) == 1:

            hits += 1

            hit_tails[val] = int(str(val)[-1])

            # print('====', hits, val)

            pass

        else:

            lst = list(map(int, str(val)))

            # print('before:', lst)

            for i in range(len(lst) - 1):

                if lst[i] > lst[i+1] + 1:

                    lst[i+1] = lst[i] - 2

                    if(i < len(lst) - 2):

                        lst[i+2:] = [9] * len(lst[i+2:])

                    val = int(''.join(map(str, lst)))

                    # print('after1:', lst)

                    break

                elif lst[i] < lst[i+1] - 1:

                    lst[i+1:] = [9] * len(lst[i+1:])

                    val = int(''.join(map(str, lst)))

                    # print('after2:', lst)

                    break

                elif i == len(lst) - 2:

                    hits += 1

                    hit_tails[val] = int(str(val)[-1])

                    # print('====', hits, val)

                    pass



    print(val)





##########

if __name__ == "__main__":

    d()

from collections import deque





def lunlun():

    k = int(eval(input()))

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



    while k > 0:

        k -= 1

        n = q.popleft()

        # print('====== popleft:', n)



        if n % 10 != 0:

            n0 = int(str(n) + str(n % 10 - 1))

            q.append(n0)

            # print('=== append:', n0)



        n1 = int(str(n) + str(n % 10))

        q.append(n1)

        # print('=== append:', n1)



        if n % 10 != 9:

            n2 = int(str(n) + str(n % 10 + 1))

            q.append(n2)

            # print('=== append:', n2)



    print(n)





##########

if __name__ == "__main__":

    lunlun()

def d():
    k = int(eval(input()))
    val = 0
    hits = 0
    hit_tails = {}
    while hits < k:
        val += 1
        if len(str(val)) == 1:
            hits += 1
            hit_tails[val] = int(str(val)[-1])
            # print('====', hits, val)
            pass
        else:
            lst = list(map(int, str(val)))
            # print('before:', lst)
            for i in range(len(lst) - 1):
                if lst[i] > lst[i + 1] + 1:
                    lst[i + 1] = lst[i] - 2
                    if i < len(lst) - 2:
                        lst[i + 2 :] = [9] * len(lst[i + 2 :])
                    val = int("".join(map(str, lst)))
                    # print('after1:', lst)
                    break
                elif lst[i] < lst[i + 1] - 1:
                    lst[i + 1 :] = [9] * len(lst[i + 1 :])
                    val = int("".join(map(str, lst)))
                    # print('after2:', lst)
                    break
                elif i == len(lst) - 2:
                    hits += 1
                    hit_tails[val] = int(str(val)[-1])
                    # print('====', hits, val)
                    pass
    print(val)


##########
if __name__ == "__main__":
    d()

from collections import deque


def lunlun():
    k = int(eval(input()))
    q = deque(list(range(1, 10)))
    while k > 0:
        k -= 1
        n = q.popleft()
        # print('====== popleft:', n)
        if n % 10 != 0:
            n0 = int(str(n) + str(n % 10 - 1))
            q.append(n0)
            # print('=== append:', n0)
        n1 = int(str(n) + str(n % 10))
        q.append(n1)
        # print('=== append:', n1)
        if n % 10 != 9:
            n2 = int(str(n) + str(n % 10 + 1))
            q.append(n2)
            # print('=== append:', n2)
    print(n)


##########
if __name__ == "__main__":
    lunlun()

-def d(): +from collections import deque + + +def lunlun(): -    val = 0 -    hits = 0 -    hit_tails = {} -    while hits < k: -        val += 1 -        if len(str(val)) == 1: -            hits += 1 -            hit_tails[val] = int(str(val)[-1]) -            # print('====', hits, val) -            pass -        else: -            lst = list(map(int, str(val))) -            # print('before:', lst) -            for i in range(len(lst) - 1): -                if lst[i] > lst[i + 1] + 1: -                    lst[i + 1] = lst[i] - 2 -                    if i < len(lst) - 2: -                        lst[i + 2 :] = [9] * len(lst[i + 2 :]) -                    val = int("".join(map(str, lst))) -                    # print('after1:', lst) -                    break -                elif lst[i] < lst[i + 1] - 1: -                    lst[i + 1 :] = [9] * len(lst[i + 1 :]) -                    val = int("".join(map(str, lst))) -                    # print('after2:', lst) -                    break -                elif i == len(lst) - 2: -                    hits += 1 -                    hit_tails[val] = int(str(val)[-1]) -                    # print('====', hits, val) -                    pass -    print(val) +    q = deque(list(range(1, 10))) +    while k > 0: +        k -= 1 +        n = q.popleft() +        # print('====== popleft:', n) +        if n % 10 != 0: +            n0 = int(str(n) + str(n % 10 - 1)) +            q.append(n0) +            # print('=== append:', n0) +        n1 = int(str(n) + str(n % 10)) +        q.append(n1) +        # print('=== append:', n1) +        if n % 10 != 9: +            n2 = int(str(n) + str(n % 10 + 1)) +            q.append(n2) +            # print('=== append:', n2) +    print(n) -    d() +    lunlun()