k=int(eval(input()))

L=[]

def f(d,now,L):

  L.append(now)

  

  if d==10:

    return

  

  for j in range(-1,2):

    v=now%10+j

    if 0<=v<=9:

      f(d+1,now*10+v,L)



for l in range(1,10):

  f(1,l,L)

L.sort()

print((L[k-1]))



      
from collections import deque



k=int(eval(input()))



lunlun=deque(i for i in range(1,10))

for _ in range(k-1):

  p=lunlun.popleft()

  if p%10!=0:

    lunlun.append(10*p+p%10-1)

  lunlun.append(10*p+p%10)

  if p%10!=9:

    lunlun.append(10*p+p%10+1)

print((lunlun.popleft()))
k = int(eval(input()))
L = []


def f(d, now, L):
    L.append(now)
    if d == 10:
        return
    for j in range(-1, 2):
        v = now % 10 + j
        if 0 <= v <= 9:
            f(d + 1, now * 10 + v, L)


for l in range(1, 10):
    f(1, l, L)
L.sort()
print((L[k - 1]))

from collections import deque

k = int(eval(input()))
lunlun = deque(i for i in range(1, 10))
for _ in range(k - 1):
    p = lunlun.popleft()
    if p % 10 != 0:
        lunlun.append(10 * p + p % 10 - 1)
    lunlun.append(10 * p + p % 10)
    if p % 10 != 9:
        lunlun.append(10 * p + p % 10 + 1)
print((lunlun.popleft()))

+from collections import deque + -L = [] - - -def f(d, now, L): -    L.append(now) -    if d == 10: -        return -    for j in range(-1, 2): -        v = now % 10 + j -        if 0 <= v <= 9: -            f(d + 1, now * 10 + v, L) - - -for l in range(1, 10): -    f(1, l, L) -L.sort() -print((L[k - 1])) +lunlun = deque(i for i in range(1, 10)) +for _ in range(k - 1): +    p = lunlun.popleft() +    if p % 10 != 0: +        lunlun.append(10 * p + p % 10 - 1) +    lunlun.append(10 * p + p % 10) +    if p % 10 != 9: +        lunlun.append(10 * p + p % 10 + 1) +print((lunlun.popleft()))