from collections import deque

k=int(eval(input()))

d=deque()

for i in range(1,10): d.append(i)

for i in range(k):

  x=d.popleft()

  if i==k-1:

    print(x)

    break

  if x%10!=0:

    d.append(10*x+x%10-1)

  d.append(10*x+x%10)

  if x%10!=9:

    d.append(10*x+x%10+1)
from collections import deque

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

for i in range(int(eval(input()))):

  x=d.popleft()

  r=x%10;c=x*10+r

  if r!=0:d.append(c-1)

  d.append(c)

  if r!=9:d.append(c+1)

print(x)
from collections import deque

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

from collections import deque

d = deque(list(range(1, 10)))
for i in range(int(eval(input()))):
    x = d.popleft()
    r = x % 10
    c = x * 10 + r
    if r != 0:
        d.append(c - 1)
    d.append(c)
    if r != 9:
        d.append(c + 1)
print(x)

-k = int(eval(input())) -d = deque() -for i in range(1, 10): -    d.append(i) -for i in range(k): +d = deque(list(range(1, 10))) +for i in range(int(eval(input()))): -    if i == k - 1: -        print(x) -        break -    if x % 10 != 0: -        d.append(10 * x + x % 10 - 1) -    d.append(10 * x + x % 10) -    if x % 10 != 9: -        d.append(10 * x + x % 10 + 1) +    r = x % 10 +    c = x * 10 + r +    if r != 0: +        d.append(c - 1) +    d.append(c) +    if r != 9: +        d.append(c + 1) +print(x)