K = int(eval(input()))

ans = []

R = [[] for _ in range(11)]

for i in range(1,10):

  R[0].append(i)

for i in range(1,11):

  R[i] = [10**i]

  if i > 1:

    for j in range(i-1):

      for r in R[i-2-j]:

        d = r//(10**(i-2-j))

        if d <= 1:

          R[i].append(10**i+r)

  for r in R[i-1]:

    d = r//(10**(i-1))

    for j in [-1,0,1]:

      if 1<= d+j <= 9:

        R[i].append((d+j)*(10**i)+r)

A = []

#print(sorted(R[0]))

#print(sorted(R[1]))

#print(sorted(R[2]))

#print(sorted(R[3]))

#print(sorted(R[4]))

#print(sorted(R[10]))

for i in range(11):

  for r in R[i]:

    A.append(r)

A.sort()

#print(len(A))

print((A[K-1]))

       

            

            

from heapq import heappush, heappop



K = int(eval(input()))

hq = []

for i in range(1,10):

  heappush(hq,i)

cnt = 0

while(cnt < K):

  x = heappop(hq)

  cnt += 1

  for i in [-1,0,1]:

    d = (x%10)+i

    if 0 <= d <= 9:

      heappush(hq,x*10+d)

print(x)

K = int(eval(input()))
ans = []
R = [[] for _ in range(11)]
for i in range(1, 10):
    R[0].append(i)
for i in range(1, 11):
    R[i] = [10**i]
    if i > 1:
        for j in range(i - 1):
            for r in R[i - 2 - j]:
                d = r // (10 ** (i - 2 - j))
                if d <= 1:
                    R[i].append(10**i + r)
    for r in R[i - 1]:
        d = r // (10 ** (i - 1))
        for j in [-1, 0, 1]:
            if 1 <= d + j <= 9:
                R[i].append((d + j) * (10**i) + r)
A = []
# print(sorted(R[0]))
# print(sorted(R[1]))
# print(sorted(R[2]))
# print(sorted(R[3]))
# print(sorted(R[4]))
# print(sorted(R[10]))
for i in range(11):
    for r in R[i]:
        A.append(r)
A.sort()
# print(len(A))
print((A[K - 1]))

from heapq import heappush, heappop

K = int(eval(input()))
hq = []
for i in range(1, 10):
    heappush(hq, i)
cnt = 0
while cnt < K:
    x = heappop(hq)
    cnt += 1
    for i in [-1, 0, 1]:
        d = (x % 10) + i
        if 0 <= d <= 9:
            heappush(hq, x * 10 + d)
print(x)

+from heapq import heappush, heappop + -ans = [] -R = [[] for _ in range(11)] +hq = [] -    R[0].append(i) -for i in range(1, 11): -    R[i] = [10**i] -    if i > 1: -        for j in range(i - 1): -            for r in R[i - 2 - j]: -                d = r // (10 ** (i - 2 - j)) -                if d <= 1: -                    R[i].append(10**i + r) -    for r in R[i - 1]: -        d = r // (10 ** (i - 1)) -        for j in [-1, 0, 1]: -            if 1 <= d + j <= 9: -                R[i].append((d + j) * (10**i) + r) -A = [] -# print(sorted(R[0])) -# print(sorted(R[1])) -# print(sorted(R[2])) -# print(sorted(R[3])) -# print(sorted(R[4])) -# print(sorted(R[10])) -for i in range(11): -    for r in R[i]: -        A.append(r) -A.sort() -# print(len(A)) -print((A[K - 1])) +    heappush(hq, i) +cnt = 0 +while cnt < K: +    x = heappop(hq) +    cnt += 1 +    for i in [-1, 0, 1]: +        d = (x % 10) + i +        if 0 <= d <= 9: +            heappush(hq, x * 10 + d) +print(x)