n=int(eval(input()))



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



if n <= 9:

    print(n)

else:

    count = 9

    while count<=n:

        i = query.pop(0)



        if i%10-1>=0:

            query.append(i*10+(i%10-1))

            count += 1

            if count == n:

                print((i*10+(i%10-1)))

                break



        query.append(i*10+(i%10))

        count += 1

        if count == n:

            print((i*10+(i%10)))

            break



        if i%10+1<=9:

            query.append(i*10+(i%10+1))

            count += 1

            if count == n:

                print((i*10+(i%10+1)))

                break
from collections import deque



n=int(eval(input()))



if n < 10:

    print(n)

else:

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

    check_num = 9

    while True:

        add_num = check_box.popleft()

        add_num = str(add_num)



        if int(add_num[-1]) - 1 >= 0:

            check_box.append(int(add_num + str(int(add_num[-1]) - 1)))

            check_num += 1

            if check_num == n:

                    print((add_num + str(int(add_num[-1]) - 1)))

                    exit()



        check_num += 1

        check_box.append(int(add_num + add_num[-1]))

        if check_num == n:

                print((add_num + add_num[-1]))

                exit()



        if int(add_num[-1]) + 1 <= 9:

            check_box.append(int(add_num + str(int(add_num[-1]) + 1)))

            check_num += 1

            if check_num == n:

                    print((add_num + str(int(add_num[-1]) + 1)))

                    exit()

        
n = int(eval(input()))
query = [1, 2, 3, 4, 5, 6, 7, 8, 9]
if n <= 9:
    print(n)
else:
    count = 9
    while count <= n:
        i = query.pop(0)
        if i % 10 - 1 >= 0:
            query.append(i * 10 + (i % 10 - 1))
            count += 1
            if count == n:
                print((i * 10 + (i % 10 - 1)))
                break
        query.append(i * 10 + (i % 10))
        count += 1
        if count == n:
            print((i * 10 + (i % 10)))
            break
        if i % 10 + 1 <= 9:
            query.append(i * 10 + (i % 10 + 1))
            count += 1
            if count == n:
                print((i * 10 + (i % 10 + 1)))
                break

from collections import deque

n = int(eval(input()))
if n < 10:
    print(n)
else:
    check_box = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    check_num = 9
    while True:
        add_num = check_box.popleft()
        add_num = str(add_num)
        if int(add_num[-1]) - 1 >= 0:
            check_box.append(int(add_num + str(int(add_num[-1]) - 1)))
            check_num += 1
            if check_num == n:
                print((add_num + str(int(add_num[-1]) - 1)))
                exit()
        check_num += 1
        check_box.append(int(add_num + add_num[-1]))
        if check_num == n:
            print((add_num + add_num[-1]))
            exit()
        if int(add_num[-1]) + 1 <= 9:
            check_box.append(int(add_num + str(int(add_num[-1]) + 1)))
            check_num += 1
            if check_num == n:
                print((add_num + str(int(add_num[-1]) + 1)))
                exit()

+from collections import deque + -query = [1, 2, 3, 4, 5, 6, 7, 8, 9] -if n <= 9: +if n < 10: -    count = 9 -    while count <= n: -        i = query.pop(0) -        if i % 10 - 1 >= 0: -            query.append(i * 10 + (i % 10 - 1)) -            count += 1 -            if count == n: -                print((i * 10 + (i % 10 - 1))) -                break -        query.append(i * 10 + (i % 10)) -        count += 1 -        if count == n: -            print((i * 10 + (i % 10))) -            break -        if i % 10 + 1 <= 9: -            query.append(i * 10 + (i % 10 + 1)) -            count += 1 -            if count == n: -                print((i * 10 + (i % 10 + 1))) -                break +    check_box = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) +    check_num = 9 +    while True: +        add_num = check_box.popleft() +        add_num = str(add_num) +        if int(add_num[-1]) - 1 >= 0: +            check_box.append(int(add_num + str(int(add_num[-1]) - 1))) +            check_num += 1 +            if check_num == n: +                print((add_num + str(int(add_num[-1]) - 1))) +                exit() +        check_num += 1 +        check_box.append(int(add_num + add_num[-1])) +        if check_num == n: +            print((add_num + add_num[-1])) +            exit() +        if int(add_num[-1]) + 1 <= 9: +            check_box.append(int(add_num + str(int(add_num[-1]) + 1))) +            check_num += 1 +            if check_num == n: +                print((add_num + str(int(add_num[-1]) + 1))) +                exit()