import sys



def is_lunlun(x):

    x_str = str(x)

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

        if abs(int(x_str[i]) - int(x_str[i+1])) > 1:

            return False

    return True



def main():

    k = int(eval(input()))



    lunlun_map = {

        0: [0, 1],

        1: [0, 1, 2],

        2: [1, 2, 3],

        3: [2, 3, 4],

        4: [3, 4, 5],

        5: [4, 5, 6],

        6: [5, 6, 7],

        7: [6, 7, 8],

        8: [7, 8, 9],

        9: [8, 9]

    }



    if k < 10:

        print(k)

        sys.exit()



    count = 9

    all_lunluns = [list(range(1, 10))]

    i = 0

    while True:

        for lunlun in all_lunluns[i]:

            least = int(str(lunlun)[-1])

            lunluns = []

            for j in lunlun_map[least]:

                new_lunlun = int(str(lunlun) + str(j))

                lunluns.append(new_lunlun)

                count += 1

                if count == k:

                    print(new_lunlun)

                    sys.exit(0)

            all_lunluns.append(lunluns)

        i += 1



if __name__ == "__main__":

    main()
# Assumed solution



from collections import deque





def main():

    k = int(eval(input()))



    queue = deque()

    for i in range(1, 10):

        queue.append(i)



    l = 0

    for _ in range(k):

        l = queue.popleft()

        r = l % 10

        if r != 0:

            queue.append(l * 10 + r - 1)

        queue.append(l * 10 + r)

        if r != 9:

            queue.append(l * 10 + r + 1)

    print(l)





if __name__ == "__main__":

    main()

import sys


def is_lunlun(x):
    x_str = str(x)
    for i in range(len(x_str) - 1):
        if abs(int(x_str[i]) - int(x_str[i + 1])) > 1:
            return False
    return True


def main():
    k = int(eval(input()))
    lunlun_map = {
        0: [0, 1],
        1: [0, 1, 2],
        2: [1, 2, 3],
        3: [2, 3, 4],
        4: [3, 4, 5],
        5: [4, 5, 6],
        6: [5, 6, 7],
        7: [6, 7, 8],
        8: [7, 8, 9],
        9: [8, 9],
    }
    if k < 10:
        print(k)
        sys.exit()
    count = 9
    all_lunluns = [list(range(1, 10))]
    i = 0
    while True:
        for lunlun in all_lunluns[i]:
            least = int(str(lunlun)[-1])
            lunluns = []
            for j in lunlun_map[least]:
                new_lunlun = int(str(lunlun) + str(j))
                lunluns.append(new_lunlun)
                count += 1
                if count == k:
                    print(new_lunlun)
                    sys.exit(0)
            all_lunluns.append(lunluns)
        i += 1


if __name__ == "__main__":
    main()

# Assumed solution
from collections import deque


def main():
    k = int(eval(input()))
    queue = deque()
    for i in range(1, 10):
        queue.append(i)
    l = 0
    for _ in range(k):
        l = queue.popleft()
        r = l % 10
        if r != 0:
            queue.append(l * 10 + r - 1)
        queue.append(l * 10 + r)
        if r != 9:
            queue.append(l * 10 + r + 1)
    print(l)


if __name__ == "__main__":
    main()

-import sys - - -def is_lunlun(x): -    x_str = str(x) -    for i in range(len(x_str) - 1): -        if abs(int(x_str[i]) - int(x_str[i + 1])) > 1: -            return False -    return True +# Assumed solution +from collections import deque -    lunlun_map = { -        0: [0, 1], -        1: [0, 1, 2], -        2: [1, 2, 3], -        3: [2, 3, 4], -        4: [3, 4, 5], -        5: [4, 5, 6], -        6: [5, 6, 7], -        7: [6, 7, 8], -        8: [7, 8, 9], -        9: [8, 9], -    } -    if k < 10: -        print(k) -        sys.exit() -    count = 9 -    all_lunluns = [list(range(1, 10))] -    i = 0 -    while True: -        for lunlun in all_lunluns[i]: -            least = int(str(lunlun)[-1]) -            lunluns = [] -            for j in lunlun_map[least]: -                new_lunlun = int(str(lunlun) + str(j)) -                lunluns.append(new_lunlun) -                count += 1 -                if count == k: -                    print(new_lunlun) -                    sys.exit(0) -            all_lunluns.append(lunluns) -        i += 1 +    queue = deque() +    for i in range(1, 10): +        queue.append(i) +    l = 0 +    for _ in range(k): +        l = queue.popleft() +        r = l % 10 +        if r != 0: +            queue.append(l * 10 + r - 1) +        queue.append(l * 10 + r) +        if r != 9: +            queue.append(l * 10 + r + 1) +    print(l)