def d_lunlun_number():

    import sys

    sys.setrecursionlimit(10**6)

    K = int(eval(input()))



    ans = []



    def dfs(num, current, digit_max):

        if current == digit_max:

            ans.append(num)

            return None

        for n in range(10):

            if abs((num % 10) - n) >= 2:

                continue

            dfs(num * 10 + n, current + 1, digit_max)



    for leading in range(1, 10):

        for d in range(1, 11):

            dfs(leading, 1, d)

    return sorted(ans)[K - 1]



print((d_lunlun_number()))
def d_lunlun_number():

    from collections import deque

    K = int(eval(input()))



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

    ans = -1

    for _ in range(K):

        ans = queue.popleft()

        lsd = ans % 10  # least significant digit

        if lsd != 0:

            queue.append(10 * ans + (lsd - 1))

        queue.append(10 * ans + lsd)

        if ans % 10 != 9:

            queue.append(10 * ans + (lsd + 1))

    return ans



print((d_lunlun_number()))
def d_lunlun_number():
    import sys

    sys.setrecursionlimit(10**6)
    K = int(eval(input()))
    ans = []

    def dfs(num, current, digit_max):
        if current == digit_max:
            ans.append(num)
            return None
        for n in range(10):
            if abs((num % 10) - n) >= 2:
                continue
            dfs(num * 10 + n, current + 1, digit_max)

    for leading in range(1, 10):
        for d in range(1, 11):
            dfs(leading, 1, d)
    return sorted(ans)[K - 1]


print((d_lunlun_number()))

def d_lunlun_number():
    from collections import deque

    K = int(eval(input()))
    queue = deque(list(range(1, 10)))
    ans = -1
    for _ in range(K):
        ans = queue.popleft()
        lsd = ans % 10  # least significant digit
        if lsd != 0:
            queue.append(10 * ans + (lsd - 1))
        queue.append(10 * ans + lsd)
        if ans % 10 != 9:
            queue.append(10 * ans + (lsd + 1))
    return ans


print((d_lunlun_number()))

-    import sys +    from collections import deque -    sys.setrecursionlimit(10**6) -    ans = [] - -    def dfs(num, current, digit_max): -        if current == digit_max: -            ans.append(num) -            return None -        for n in range(10): -            if abs((num % 10) - n) >= 2: -                continue -            dfs(num * 10 + n, current + 1, digit_max) - -    for leading in range(1, 10): -        for d in range(1, 11): -            dfs(leading, 1, d) -    return sorted(ans)[K - 1] +    queue = deque(list(range(1, 10))) +    ans = -1 +    for _ in range(K): +        ans = queue.popleft() +        lsd = ans % 10  # least significant digit +        if lsd != 0: +            queue.append(10 * ans + (lsd - 1)) +        queue.append(10 * ans + lsd) +        if ans % 10 != 9: +            queue.append(10 * ans + (lsd + 1)) +    return ans