import numpy as np



K = int(eval(input()))



top = np.ones(10, dtype=int)

adj = np.eye(10, dtype=int)

adj[1:, :-1] += np.eye(9, dtype=int)

adj[:-1, 1:] += np.eye(9, dtype=int)



counts = [top]

tmp = top

for _ in range(10):

    tmp = np.dot(tmp, adj)

    counts.append(tmp)



for i in range(10):

    for j in range(1, 10):

        if K > counts[i][j]:

            K -= counts[i][j]

        else:

            break

    else:

        continue

    break



ans = [-1] * (i + 1)

ans[i] = j



for d in range(i, 0, -1):

    for k in range(max(0, j - 1), min(9, j + 1) + 1):

        if K > counts[d - 1][k]:

            K -= counts[d - 1][k]

        else:

            ans[d - 1] = k

            j = k

            break





print(("".join(list(map(str, ans))[::-1])))

from collections import deque



K = int(eval(input()))



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



for i in range(K):

    x = q.popleft()

    r = x % 10

    y = 10 * x + r

    if r != 0:

        q.append(y - 1)

    q.append(y)

    if r != 9:

        q.append(y + 1)



print(x)

import numpy as np

K = int(eval(input()))
top = np.ones(10, dtype=int)
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)
counts = [top]
tmp = top
for _ in range(10):
    tmp = np.dot(tmp, adj)
    counts.append(tmp)
for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break
ans = [-1] * (i + 1)
ans[i] = j
for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break
print(("".join(list(map(str, ans))[::-1])))

from collections import deque

K = int(eval(input()))
q = deque(list(range(1, 10)))
for i in range(K):
    x = q.popleft()
    r = x % 10
    y = 10 * x + r
    if r != 0:
        q.append(y - 1)
    q.append(y)
    if r != 9:
        q.append(y + 1)
print(x)

-import numpy as np +from collections import deque -top = np.ones(10, dtype=int) -adj = np.eye(10, dtype=int) -adj[1:, :-1] += np.eye(9, dtype=int) -adj[:-1, 1:] += np.eye(9, dtype=int) -counts = [top] -tmp = top -for _ in range(10): -    tmp = np.dot(tmp, adj) -    counts.append(tmp) -for i in range(10): -    for j in range(1, 10): -        if K > counts[i][j]: -            K -= counts[i][j] -        else: -            break -    else: -        continue -    break -ans = [-1] * (i + 1) -ans[i] = j -for d in range(i, 0, -1): -    for k in range(max(0, j - 1), min(9, j + 1) + 1): -        if K > counts[d - 1][k]: -            K -= counts[d - 1][k] -        else: -            ans[d - 1] = k -            j = k -            break -print(("".join(list(map(str, ans))[::-1]))) +q = deque(list(range(1, 10))) +for i in range(K): +    x = q.popleft() +    r = x % 10 +    y = 10 * x + r +    if r != 0: +        q.append(y - 1) +    q.append(y) +    if r != 9: +        q.append(y + 1) +print(x)