# import numpy as np

# import math

# import copy

from collections import deque

import sys

input = sys.stdin.readline

# sys.setrecursionlimit(10000)





def main():

    K = int(eval(input()))



    queue = deque()



    for i in range(1,10):

        queue.append(i)



    for i in range(K):

        x = queue.popleft()

        d = x % 10

        temp = 10 * x + d

        if d != 0:

            queue.append(temp - 1)

        queue.append(temp)

        if d != 9:

            queue.append(temp + 1)



    print(x)







main()

# import numpy as np

# import math

# import copy

from collections import deque

import sys

input = sys.stdin.readline

# sys.setrecursionlimit(10000)





def main():

    K = int(eval(input()))



    pre = [i for i in range(1,10)]

    now = []



    if K <= 10:

        print(K)

        sys.exit()



    count = 9



    for i in range(2,11):

        for j in pre:

            for k in range(-1,2):

                d = j % 10 + k

                if (d < 0) | (d > 9):

                    continue

                temp = j * 10 + d

                now.append(temp)

                count += 1

                if count == K:

                    print(temp)

                    sys.exit()

        pre = now







main()

# import numpy as np
# import math
# import copy
from collections import deque
import sys

input = sys.stdin.readline
# sys.setrecursionlimit(10000)
def main():
    K = int(eval(input()))
    queue = deque()
    for i in range(1, 10):
        queue.append(i)
    for i in range(K):
        x = queue.popleft()
        d = x % 10
        temp = 10 * x + d
        if d != 0:
            queue.append(temp - 1)
        queue.append(temp)
        if d != 9:
            queue.append(temp + 1)
    print(x)


main()

# import numpy as np
# import math
# import copy
from collections import deque
import sys

input = sys.stdin.readline
# sys.setrecursionlimit(10000)
def main():
    K = int(eval(input()))
    pre = [i for i in range(1, 10)]
    now = []
    if K <= 10:
        print(K)
        sys.exit()
    count = 9
    for i in range(2, 11):
        for j in pre:
            for k in range(-1, 2):
                d = j % 10 + k
                if (d < 0) | (d > 9):
                    continue
                temp = j * 10 + d
                now.append(temp)
                count += 1
                if count == K:
                    print(temp)
                    sys.exit()
        pre = now


main()

-    queue = deque() -    for i in range(1, 10): -        queue.append(i) -    for i in range(K): -        x = queue.popleft() -        d = x % 10 -        temp = 10 * x + d -        if d != 0: -            queue.append(temp - 1) -        queue.append(temp) -        if d != 9: -            queue.append(temp + 1) -    print(x) +    pre = [i for i in range(1, 10)] +    now = [] +    if K <= 10: +        print(K) +        sys.exit() +    count = 9 +    for i in range(2, 11): +        for j in pre: +            for k in range(-1, 2): +                d = j % 10 + k +                if (d < 0) | (d > 9): +                    continue +                temp = j * 10 + d +                now.append(temp) +                count += 1 +                if count == K: +                    print(temp) +                    sys.exit() +        pre = now