def f(N): # N is string

    k = len(N)

    dp = [[[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)] for _ in range(k+1)]

    for j in range(10):

        dp[1][0][0][j]=(j==int(N[0]))

        dp[1][0][1][j]=0

        dp[1][1][0][j]=(j<int(N[0]))

        dp[1][1][1][j]=0

    for i in range(2,k+1):

        for j in range(10):

            for m in range(10):

                dp[i][0][1][j] += (dp[i-1][0][0][m]+dp[i-1][0][1][m])*(abs(m-j)<=1)*(j==int(N[i-1]))

            dp[i][1][0][j]=1

            for m in range(10):

                dp[i][1][1][j] += (dp[i-1][0][0][m]+dp[i-1][0][1][m])*(abs(m-j)<=1)*(j<int(N[i-1]))\

                                    +dp[i-1][1][1][m]*(abs(m-j)<=1)

            for m in range(1,10):

                dp[i][1][1][j] += dp[i-1][1][0][m]*(abs(m-j)<=1)

    cnt = 0

    for j in range(10):

        cnt += dp[k][0][0][j]+dp[k][0][1][j]+dp[k][1][0][j]+dp[k][1][1][j]

    return cnt-1

K = int(input())

low = 0

high = 4*10**9

while high-low>1:

    mid = (high+low)//2

    n = f(str(mid))

    if n<K:

        low = mid

    elif n>=K:

        high = mid

print(high)

from collections import deque

K = int(eval(input()))

A = deque([str(i) for i in range(1,10)])

cnt = 0

while cnt<K:

    a = A.popleft()

    cnt += 1

    if a[-1]=="0":

        a0 = a+"0"

        a1 = a+"1"

        A.append(a0)

        A.append(a1)

    elif a[-1]=="9":

        a0 = a+"8"

        a1 = a+"9"

        A.append(a0)

        A.append(a1)

    else:

        b = a[-1]

        a0 = a+str(int(b)-1)

        a1 = a+b

        a2 = a+str(int(b)+1)

        A.append(a0)

        A.append(a1)

        A.append(a2)

print(a)
def f(N):  # N is string
    k = len(N)
    dp = [
        [[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)]
        for _ in range(k + 1)
    ]
    for j in range(10):
        dp[1][0][0][j] = j == int(N[0])
        dp[1][0][1][j] = 0
        dp[1][1][0][j] = j < int(N[0])
        dp[1][1][1][j] = 0
    for i in range(2, k + 1):
        for j in range(10):
            for m in range(10):
                dp[i][0][1][j] += (
                    (dp[i - 1][0][0][m] + dp[i - 1][0][1][m])
                    * (abs(m - j) <= 1)
                    * (j == int(N[i - 1]))
                )
            dp[i][1][0][j] = 1
            for m in range(10):
                dp[i][1][1][j] += (dp[i - 1][0][0][m] + dp[i - 1][0][1][m]) * (
                    abs(m - j) <= 1
                ) * (j < int(N[i - 1])) + dp[i - 1][1][1][m] * (abs(m - j) <= 1)
            for m in range(1, 10):
                dp[i][1][1][j] += dp[i - 1][1][0][m] * (abs(m - j) <= 1)
    cnt = 0
    for j in range(10):
        cnt += dp[k][0][0][j] + dp[k][0][1][j] + dp[k][1][0][j] + dp[k][1][1][j]
    return cnt - 1


K = int(input())
low = 0
high = 4 * 10**9
while high - low > 1:
    mid = (high + low) // 2
    n = f(str(mid))
    if n < K:
        low = mid
    elif n >= K:
        high = mid
print(high)

from collections import deque

K = int(eval(input()))
A = deque([str(i) for i in range(1, 10)])
cnt = 0
while cnt < K:
    a = A.popleft()
    cnt += 1
    if a[-1] == "0":
        a0 = a + "0"
        a1 = a + "1"
        A.append(a0)
        A.append(a1)
    elif a[-1] == "9":
        a0 = a + "8"
        a1 = a + "9"
        A.append(a0)
        A.append(a1)
    else:
        b = a[-1]
        a0 = a + str(int(b) - 1)
        a1 = a + b
        a2 = a + str(int(b) + 1)
        A.append(a0)
        A.append(a1)
        A.append(a2)
print(a)

-def f(N):  # N is string -    k = len(N) -    dp = [ -        [[[0 for _ in range(10)] for _ in range(2)] for _ in range(2)] -        for _ in range(k + 1) -    ] -    for j in range(10): -        dp[1][0][0][j] = j == int(N[0]) -        dp[1][0][1][j] = 0 -        dp[1][1][0][j] = j < int(N[0]) -        dp[1][1][1][j] = 0 -    for i in range(2, k + 1): -        for j in range(10): -            for m in range(10): -                dp[i][0][1][j] += ( -                    (dp[i - 1][0][0][m] + dp[i - 1][0][1][m]) -                    * (abs(m - j) <= 1) -                    * (j == int(N[i - 1])) -                ) -            dp[i][1][0][j] = 1 -            for m in range(10): -                dp[i][1][1][j] += (dp[i - 1][0][0][m] + dp[i - 1][0][1][m]) * ( -                    abs(m - j) <= 1 -                ) * (j < int(N[i - 1])) + dp[i - 1][1][1][m] * (abs(m - j) <= 1) -            for m in range(1, 10): -                dp[i][1][1][j] += dp[i - 1][1][0][m] * (abs(m - j) <= 1) -    cnt = 0 -    for j in range(10): -        cnt += dp[k][0][0][j] + dp[k][0][1][j] + dp[k][1][0][j] + dp[k][1][1][j] -    return cnt - 1 +from collections import deque - -K = int(input()) -low = 0 -high = 4 * 10**9 -while high - low > 1: -    mid = (high + low) // 2 -    n = f(str(mid)) -    if n < K: -        low = mid -    elif n >= K: -        high = mid -print(high) +K = int(eval(input())) +A = deque([str(i) for i in range(1, 10)]) +cnt = 0 +while cnt < K: +    a = A.popleft() +    cnt += 1 +    if a[-1] == "0": +        a0 = a + "0" +        a1 = a + "1" +        A.append(a0) +        A.append(a1) +    elif a[-1] == "9": +        a0 = a + "8" +        a1 = a + "9" +        A.append(a0) +        A.append(a1) +    else: +        b = a[-1] +        a0 = a + str(int(b) - 1) +        a1 = a + b +        a2 = a + str(int(b) + 1) +        A.append(a0) +        A.append(a1) +        A.append(a2) +print(a)