from collections import deque

K = int(eval(input()))

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



for _ in range(K-1):

  q = Q.popleft()

  if q%10 != 0:

    Q.append(q*10+q%10-1)

  Q.append(q*10+q%10)

  if q%10 != 9:

    Q.append(q*10+q%10+1)

print((Q.popleft()))
from collections import deque

K = int(eval(input()))

q = deque([1,2,3,4,5,6,7,8,9])



for i in range(K):

  num = q.popleft()

  if num%10 != 0:

    q.append(num*10+num%10-1)

  q.append(num*10+num%10)

  if num%10 != 9:

    q.append(num*10+num%10+1)



print(num)
from collections import deque

K = int(eval(input()))
Q = deque([i for i in range(1, 10)])
for _ in range(K - 1):
    q = Q.popleft()
    if q % 10 != 0:
        Q.append(q * 10 + q % 10 - 1)
    Q.append(q * 10 + q % 10)
    if q % 10 != 9:
        Q.append(q * 10 + q % 10 + 1)
print((Q.popleft()))

from collections import deque

K = int(eval(input()))
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
    num = q.popleft()
    if num % 10 != 0:
        q.append(num * 10 + num % 10 - 1)
    q.append(num * 10 + num % 10)
    if num % 10 != 9:
        q.append(num * 10 + num % 10 + 1)
print(num)

-Q = deque([i for i in range(1, 10)]) -for _ in range(K - 1): -    q = Q.popleft() -    if q % 10 != 0: -        Q.append(q * 10 + q % 10 - 1) -    Q.append(q * 10 + q % 10) -    if q % 10 != 9: -        Q.append(q * 10 + q % 10 + 1) -print((Q.popleft())) +q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) +for i in range(K): +    num = q.popleft() +    if num % 10 != 0: +        q.append(num * 10 + num % 10 - 1) +    q.append(num * 10 + num % 10) +    if num % 10 != 9: +        q.append(num * 10 + num % 10 + 1) +print(num)