from collections import *

k=int(eval(input()));q=deque(list(range(1,10)));c=0

while c<k:

  t=q.popleft()

  for j in range(max(t%10-1,0),min(t%10+2,10)): q+=[t*10+j]

  c+=1

print(t)
k=int(eval(input()));l=list(range(1,10))

for i in l:

  if len(l)>k: break

  for j in range(max(i%10-1,0),min(i%10+2,10)): l.append(i*10+j)

print((l[k-1]))
from collections import *

k = int(eval(input()))
q = deque(list(range(1, 10)))
c = 0
while c < k:
    t = q.popleft()
    for j in range(max(t % 10 - 1, 0), min(t % 10 + 2, 10)):
        q += [t * 10 + j]
    c += 1
print(t)

k = int(eval(input()))
l = list(range(1, 10))
for i in l:
    if len(l) > k:
        break
    for j in range(max(i % 10 - 1, 0), min(i % 10 + 2, 10)):
        l.append(i * 10 + j)
print((l[k - 1]))

-from collections import * - -q = deque(list(range(1, 10))) -c = 0 -while c < k: -    t = q.popleft() -    for j in range(max(t % 10 - 1, 0), min(t % 10 + 2, 10)): -        q += [t * 10 + j] -    c += 1 -print(t) +l = list(range(1, 10)) +for i in l: +    if len(l) > k: +        break +    for j in range(max(i % 10 - 1, 0), min(i % 10 + 2, 10)): +        l.append(i * 10 + j) +print((l[k - 1]))