import sys

sys.setrecursionlimit(10**7)

L = []

def lunlun(x, cnt, c):

  if cnt == 10:

    L.append(int(x))

    return

  e = int(x[-1])

  if c:

    for i in range(max(e-1, 0), min(e+2, 10)):

      lunlun(x+str(i), cnt+1, 1)

  else:

    lunlun(x+"0", cnt+1, 0)

    for i in range(1, 10):

      lunlun(x+str(i), cnt+1, 1)

lunlun("0", 1, 0)

for i in range(1, 10):

  lunlun(str(i), 1, 1)



k = int(eval(input()))

ans = L[k]

print(ans)
from collections import deque

que = deque()

L = []

k = int(eval(input()))

for i in range(1, 10):

  L.append(str(i))

  que.append(str(i))

while len(L) < k:

  top = que.popleft()

  e = int(top[-1])

  for i in range(max(e-1, 0), min(e+2, 10)):

    x = top + str(i)

    L.append(x)

    que.append(x)

ans = L[k-1]

print(ans)
import sys

sys.setrecursionlimit(10**7)
L = []


def lunlun(x, cnt, c):
    if cnt == 10:
        L.append(int(x))
        return
    e = int(x[-1])
    if c:
        for i in range(max(e - 1, 0), min(e + 2, 10)):
            lunlun(x + str(i), cnt + 1, 1)
    else:
        lunlun(x + "0", cnt + 1, 0)
        for i in range(1, 10):
            lunlun(x + str(i), cnt + 1, 1)


lunlun("0", 1, 0)
for i in range(1, 10):
    lunlun(str(i), 1, 1)
k = int(eval(input()))
ans = L[k]
print(ans)

from collections import deque

que = deque()
L = []
k = int(eval(input()))
for i in range(1, 10):
    L.append(str(i))
    que.append(str(i))
while len(L) < k:
    top = que.popleft()
    e = int(top[-1])
    for i in range(max(e - 1, 0), min(e + 2, 10)):
        x = top + str(i)
        L.append(x)
        que.append(x)
ans = L[k - 1]
print(ans)

-import sys +from collections import deque -sys.setrecursionlimit(10**7) +que = deque() - - -def lunlun(x, cnt, c): -    if cnt == 10: -        L.append(int(x)) -        return -    e = int(x[-1]) -    if c: -        for i in range(max(e - 1, 0), min(e + 2, 10)): -            lunlun(x + str(i), cnt + 1, 1) -    else: -        lunlun(x + "0", cnt + 1, 0) -        for i in range(1, 10): -            lunlun(x + str(i), cnt + 1, 1) - - -lunlun("0", 1, 0) +k = int(eval(input())) -    lunlun(str(i), 1, 1) -k = int(eval(input())) -ans = L[k] +    L.append(str(i)) +    que.append(str(i)) +while len(L) < k: +    top = que.popleft() +    e = int(top[-1]) +    for i in range(max(e - 1, 0), min(e + 2, 10)): +        x = top + str(i) +        L.append(x) +        que.append(x) +ans = L[k - 1]