from collections import deque

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines





def main():

    K = int(readline())



    queue = deque([])

    for i in range(1,10):

        queue.append(i)

    

    for i in range(K):

        x = queue.popleft()

        r = x % 10

        if r != 0:

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

        queue.append(10*x + r)

        if x % 10 != 9:

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

    

    print(x)





if __name__ == "__main__":

    main()

# 桁dp + 二分探索

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines



def lunlun_num(N):

    N = str(N)

    L = len(N)



    dp = [[0]*10 for j in range(L)]

    for j in range(1,int(N[0])):

        dp[0][j] = 1



    flag = True

    for i in range(L-1):

        d = int(N[i+1])

        b = int(N[i])

        

        dp[i+1][0] += dp[i][0] + dp[i][1]

        dp[i+1][9] += dp[i][8] + dp[i][9]

        for j in range(1,9):

            dp[i+1][j] += dp[i][j-1] + dp[i][j] + dp[i][j+1]

        for j in range(1,10):

            dp[i+1][j] += 1



        if flag:

            if d < b - 1:

                flag = False

            elif d <= b + 1:

                for j in range(max(0, b-1),d):

                    dp[i+1][j] += 1

            else:

                for j in range(max(0, b-1),b+2):

                    dp[i+1][j] += 1

                    flag = False



    return sum(dp[L-1]) + 1 if flag else sum(dp[L-1])





def main():

    K = int(readline())



    # xを決め打って二分探索

    left = 0

    right = 10**10

    while left + 1 < right:

        x = (left + right) // 2



        if lunlun_num(x) >= K:

            right = x

        else:

            left = x

    

    print(right)





if __name__ == "__main__":

    main()

from collections import deque
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    K = int(readline())
    queue = deque([])
    for i in range(1, 10):
        queue.append(i)
    for i in range(K):
        x = queue.popleft()
        r = x % 10
        if r != 0:
            queue.append(10 * x + r - 1)
        queue.append(10 * x + r)
        if x % 10 != 9:
            queue.append(10 * x + r + 1)
    print(x)


if __name__ == "__main__":
    main()

# 桁dp + 二分探索
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def lunlun_num(N):
    N = str(N)
    L = len(N)
    dp = [[0] * 10 for j in range(L)]
    for j in range(1, int(N[0])):
        dp[0][j] = 1
    flag = True
    for i in range(L - 1):
        d = int(N[i + 1])
        b = int(N[i])
        dp[i + 1][0] += dp[i][0] + dp[i][1]
        dp[i + 1][9] += dp[i][8] + dp[i][9]
        for j in range(1, 9):
            dp[i + 1][j] += dp[i][j - 1] + dp[i][j] + dp[i][j + 1]
        for j in range(1, 10):
            dp[i + 1][j] += 1
        if flag:
            if d < b - 1:
                flag = False
            elif d <= b + 1:
                for j in range(max(0, b - 1), d):
                    dp[i + 1][j] += 1
            else:
                for j in range(max(0, b - 1), b + 2):
                    dp[i + 1][j] += 1
                    flag = False
    return sum(dp[L - 1]) + 1 if flag else sum(dp[L - 1])


def main():
    K = int(readline())
    # xを決め打って二分探索
    left = 0
    right = 10**10
    while left + 1 < right:
        x = (left + right) // 2
        if lunlun_num(x) >= K:
            right = x
        else:
            left = x
    print(right)


if __name__ == "__main__":
    main()

-from collections import deque +# 桁dp + 二分探索 +def lunlun_num(N): +    N = str(N) +    L = len(N) +    dp = [[0] * 10 for j in range(L)] +    for j in range(1, int(N[0])): +        dp[0][j] = 1 +    flag = True +    for i in range(L - 1): +        d = int(N[i + 1]) +        b = int(N[i]) +        dp[i + 1][0] += dp[i][0] + dp[i][1] +        dp[i + 1][9] += dp[i][8] + dp[i][9] +        for j in range(1, 9): +            dp[i + 1][j] += dp[i][j - 1] + dp[i][j] + dp[i][j + 1] +        for j in range(1, 10): +            dp[i + 1][j] += 1 +        if flag: +            if d < b - 1: +                flag = False +            elif d <= b + 1: +                for j in range(max(0, b - 1), d): +                    dp[i + 1][j] += 1 +            else: +                for j in range(max(0, b - 1), b + 2): +                    dp[i + 1][j] += 1 +                    flag = False +    return sum(dp[L - 1]) + 1 if flag else sum(dp[L - 1]) + + -    queue = deque([]) -    for i in range(1, 10): -        queue.append(i) -    for i in range(K): -        x = queue.popleft() -        r = x % 10 -        if r != 0: -            queue.append(10 * x + r - 1) -        queue.append(10 * x + r) -        if x % 10 != 9: -            queue.append(10 * x + r + 1) -    print(x) +    # xを決め打って二分探索 +    left = 0 +    right = 10**10 +    while left + 1 < right: +        x = (left + right) // 2 +        if lunlun_num(x) >= K: +            right = x +        else: +            left = x +    print(right)