import heapq

K=int(eval(input()))

if K<10:

  print(K)

  exit()

  

nums=[1, 2, 3, 4, 5, 6, 7, 8, 9]

heapq.heapify(nums)

for i in range(K):

  value=heapq.heappop(nums)

  tmp=str(value)

  if tmp[-1]=='0':

    cand=[int(tmp+'0'), int(tmp+'1')]

  elif tmp[-1]=='9':

    cand=[int(tmp+'8'), int(tmp+'9')]

  else:

    h=int(tmp[-1])

    cand=[int(tmp+str(h-1)), int(tmp+str(h)), int(tmp+str(h+1))]

  for c in cand:

    heapq.heappush(nums, c)

print(value)
from collections import deque

K=int(eval(input()))



q=deque()

for i in range(1, 10):

  q.append(i)

  

for i in range(K):

  v=q.popleft()

  if v%10!=0:

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

    

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

  

  if v%10!=9:

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

    

print(v)
import heapq

K = int(eval(input()))
if K < 10:
    print(K)
    exit()
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(nums)
for i in range(K):
    value = heapq.heappop(nums)
    tmp = str(value)
    if tmp[-1] == "0":
        cand = [int(tmp + "0"), int(tmp + "1")]
    elif tmp[-1] == "9":
        cand = [int(tmp + "8"), int(tmp + "9")]
    else:
        h = int(tmp[-1])
        cand = [int(tmp + str(h - 1)), int(tmp + str(h)), int(tmp + str(h + 1))]
    for c in cand:
        heapq.heappush(nums, c)
print(value)

from collections import deque

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

-import heapq +from collections import deque -if K < 10: -    print(K) -    exit() -nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] -heapq.heapify(nums) +q = deque() +for i in range(1, 10): +    q.append(i) -    value = heapq.heappop(nums) -    tmp = str(value) -    if tmp[-1] == "0": -        cand = [int(tmp + "0"), int(tmp + "1")] -    elif tmp[-1] == "9": -        cand = [int(tmp + "8"), int(tmp + "9")] -    else: -        h = int(tmp[-1]) -        cand = [int(tmp + str(h - 1)), int(tmp + str(h)), int(tmp + str(h + 1))] -    for c in cand: -        heapq.heappush(nums, c) -print(value) +    v = q.popleft() +    if v % 10 != 0: +        q.append(10 * v + v % 10 - 1) +    q.append(10 * v + v % 10) +    if v % 10 != 9: +        q.append(10 * v + v % 10 + 1) +print(v)