from collections import deque

k = int(eval(input()))

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

for _ in range(k):

  x = Q.popleft()

  y = x % 10

  z = 10*x + y

  if y != 0:

    Q += [z-1]

  Q += [z]

  if y != 9:

    Q += [z+1]

print(x)
from collections import deque

k = int(eval(input()))



Q = deque(list(range(1, 10))) #るんるん数を格納するキュー

# Q: 1 2 3 4 5 6 7 8 9



for i in range(k):

  x = Q.popleft()

  #x = 1 <--  Q: 2 3 4 5 6 7 8 9

  last_digit = x % 10 # 1 一番目の桁の値

  if last_digit == 0:

        Q.append(10*x + 0)

        Q.append(10*x + 1)



  elif last_digit == 9:

        Q.append(10*x + 8)

        Q.append(10*x + 9)



  else: # 1<=last_digit <=8

        Q.append(10*x + last_digit - 1)

        Q.append(10*x + last_digit)

        Q.append(10*x + last_digit + 1)

print(x)
from collections import deque

k = int(eval(input()))
Q = deque(list(range(1, 10)))
for _ in range(k):
    x = Q.popleft()
    y = x % 10
    z = 10 * x + y
    if y != 0:
        Q += [z - 1]
    Q += [z]
    if y != 9:
        Q += [z + 1]
print(x)

from collections import deque

k = int(eval(input()))
Q = deque(list(range(1, 10)))  # るんるん数を格納するキュー
# Q: 1 2 3 4 5 6 7 8 9
for i in range(k):
    x = Q.popleft()
    # x = 1 <--  Q: 2 3 4 5 6 7 8 9
    last_digit = x % 10  # 1 一番目の桁の値
    if last_digit == 0:
        Q.append(10 * x + 0)
        Q.append(10 * x + 1)
    elif last_digit == 9:
        Q.append(10 * x + 8)
        Q.append(10 * x + 9)
    else:  # 1<=last_digit <=8
        Q.append(10 * x + last_digit - 1)
        Q.append(10 * x + last_digit)
        Q.append(10 * x + last_digit + 1)
print(x)

-Q = deque(list(range(1, 10))) -for _ in range(k): +Q = deque(list(range(1, 10)))  # るんるん数を格納するキュー +# Q: 1 2 3 4 5 6 7 8 9 +for i in range(k): -    y = x % 10 -    z = 10 * x + y -    if y != 0: -        Q += [z - 1] -    Q += [z] -    if y != 9: -        Q += [z + 1] +    # x = 1 <--  Q: 2 3 4 5 6 7 8 9 +    last_digit = x % 10  # 1 一番目の桁の値 +    if last_digit == 0: +        Q.append(10 * x + 0) +        Q.append(10 * x + 1) +    elif last_digit == 9: +        Q.append(10 * x + 8) +        Q.append(10 * x + 9) +    else:  # 1<=last_digit <=8 +        Q.append(10 * x + last_digit - 1) +        Q.append(10 * x + last_digit) +        Q.append(10 * x + last_digit + 1)