CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque
K = int(eval(input()))
q = deque([0])

cnt = 0
ans = []
while q:
  a = q.popleft()
  r = a % 10
  a *= 10
  for i in range(10):
    if abs(r - i) <= 1 or a == 0:
      if cnt < K and a + i != 0:
        q.append(a + i)
        ans.append(a + i)
        cnt += 1

print((ans[-1]))

# Optimized solution
from collections import deque
K = int(eval(input()))
q = deque([0])

cnt = 0
while q:
  n = q.popleft()
  r = n % 10; n *= 10;
  for i in range(10):
    if abs(r - i) <= 1 or n == 0:
      if n + i != 0:
        q.append(n + i)
        cnt += 1
        if cnt == K:
          print((n+i))
          exit()
# Original solution
def lunlun(n):
	nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
	while len(nums) < n:
		old_nums = list(nums)
		for num in old_nums:
			num = str(num)
			if num[-1] == '0':
				adds = num + '0'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '1'
				if int(adds) not in nums:
					nums.add(int(adds))
			elif num[-1] == '9':
				adds = num + '9'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '8'
				if int(adds) not in nums:
					nums.add(int(adds))
			else:
				adds = num + str(int(num[-1]) - 1)
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]))
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]) + 1)
				if int(adds) not in nums:
					nums.add(int(adds))
			if num[0] == '1':
				adds = '1' + num
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = '2' + num
				if int(adds) not in nums:
					nums.add(int(adds))
			elif num[0] == '9':
				adds = '8' + num
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = '9' + num
				if int(adds) not in nums:
					nums.add(int(adds))
			else:
				adds = str(int(num[0]) - 1) + num
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = str(int(num[0])) + num
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = str(int(num[0]) + 1) + num
				if int(adds) not in nums:
					nums.add(int(adds))

	nums = list(nums)
	nums = sorted(nums)
	return nums[n - 1]

n = int(eval(input()))
print((lunlun(n)))

# Optimized solution
def lunlun(n):
	nums = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
	while len(nums) < n:
		old_nums = list(nums)
		for num in old_nums:
			num = str(num)
			if num[-1] == '0':
				adds = num + '0'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '1'
				if int(adds) not in nums:
					nums.add(int(adds))
			elif num[-1] == '9':
				adds = num + '9'
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + '8'
				if int(adds) not in nums:
					nums.add(int(adds))
			else:
				adds = num + str(int(num[-1]) - 1)
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]))
				if int(adds) not in nums:
					nums.add(int(adds))
				adds = num + str(int(num[-1]) + 1)
				if int(adds) not in nums:
					nums.add(int(adds))
			# if num[0] == '1':
			# 	adds = '1' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = '2' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# elif num[0] == '9':
			# 	adds = '8' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = '9' + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# else:
			# 	adds = str(int(num[0]) - 1) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = str(int(num[0])) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))
			# 	adds = str(int(num[0]) + 1) + num
			# 	if int(adds) not in nums:
			# 		nums.add(int(adds))

	nums = list(nums)
	nums = sorted(nums)
	return nums[n - 1]

n = int(eval(input()))
print((lunlun(n)))
# Original solution
import sys
sys.setrecursionlimit(10**9)

k=int(eval(input()))

def dfs(keta,num):
  lunlun.append(int(num))
  if keta==10:
    return

  min_v=max(0,int(num[-1])-1)
  max_v=min(9,int(num[-1])+1)

  for i in range(min_v,max_v+1):
    dfs(keta+1,num+str(i))

lunlun=[]
for i in range(1,10):
  dfs(0,str(i))

lunlun.sort()
print((lunlun[k-1]))

# Optimized solution
k=int(eval(input()))

def dfs(keta,num):
  global ans
  ans.append(int(''.join(num)))

  if keta==10:
    return

  min_n=max(0,int(num[-1])-1)
  max_n=min(9,int(num[-1])+1)
  for i in range(min_n,max_n+1):
    dfs(keta+1,num+[str(i)])

ans=[]
for i in range(1,10):
  dfs(1,[str(i)])

ans.sort()
print((ans[k-1]))
# Original solution
#!/usr/bin/env python3
from heapq import *

a = [*list(range(1, 10))]
heapify(a)
i = 0
k = int(eval(input()))
c = 0
while True:
    t = str(heappop(a))
    i += 1
    if i == k:
        break
    if t[-1] != "0":
        heappush(a, int(t + str(int(t[-1]) - 1)))
    heappush(a, int(t + t[-1]))
    if t[-1] != "9":
        heappush(a, int(t + str(int(t[-1]) + 1)))
print(t)


# Optimized solution
# !/usr/bin/env python3
# from heapq import *
#
# a = [*range(1, 10)]
# heapify(a)
# i = 0
# k = int(input())
# c = 0
# while True:
#    t = str(heappop(a))
#    i += 1
#    if i == k:
#        break
#    if t[-1] != "0":
#        heappush(a, int(t + str(int(t[-1]) - 1)))
#    heappush(a, int(t + t[-1]))
#    if t[-1] != "9":
#        heappush(a, int(t + str(int(t[-1]) + 1)))
# print(t)

from collections import deque

a = deque(list(range(1, 10)))
for _ in range(int(eval(input()))):
    i = a.popleft()
    m = i % 10
    i = 10 * i + m
    if m > 0:
        a.append(i - 1)
    a.append(i)
    if m < 9:
        a.append(i + 1)
print((i // 10))
# Original solution
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)

# Optimized solution
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)
# Original solution
import queue
def solved(n):
    if n <= 9:
        return n
    nums = queue.Queue()
    for i in range(1, 10):
        nums.put(i)
    cnt = 9
    for i in range(cnt, n):
        i_num = nums.get()
        ini_num = i_num % 10
        for j in range(max(0, ini_num - 1), min(10, ini_num + 2)):
            nums.put(i_num * 10 + j)
            cnt += 1
            if cnt == n:
                return i_num * 10 + j
k = int(eval(input()))
num = queue.Queue()
print((solved(k)))

# Optimized solution
import queue
def solve(n):
    if n < 10:
        return n
    cnt = 0
    next = queue.Queue()
    for i in range(1, 10):
        next.put(i)
        cnt += 1
    while True:
        i = next.get()
        for j in range(i % 10 - 1, i % 10 + 2):
            if j < 0 or 9 < j:
                continue
            next.put(i * 10 + j)
            cnt += 1
            if cnt == n:
                return i * 10 + j
k = int(eval(input()))
next = queue.Queue
print((solve(k)))
# Original solution
def main():
    from collections import deque
    k = int(eval(input()))
    ans = 0
    que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
    x = 0
    for _ in range(k):
        x = que.popleft()

        p = x % 10
        e = 10 * x
        if p != 0:
            a = e + p - 1
            que.append(a)
        b = e + p
        que.append(b)
        if p != 9:
            c = e + p + 1
            que.append(c)
    print(x)


if __name__ == '__main__':
    main()


# Optimized solution
def LunLun(k, count, base):
    nx = []
    n = len(base)
    if count + n >= k:
        print((base[k - count - 1]))
        return
    for x in base:
        count += 1
        p = x % 10
        x *= 10
        a = x + p - 1
        b = a + 1
        c = b + 1
        n = 3
        if p == 0:
            n -= 1
            nx.extend([b, c])
        elif p == 9:
            n -= 1
            nx.extend([a, b])
        else:
            nx.extend([a, b, c])

    LunLun(k, count, nx)


def main():
    k = int(eval(input()))
    base = list(range(1, 10))
    LunLun(k, 0, base)


if __name__ == '__main__':
    main()
# Original solution
def LunLun(k, count, base):
    nx = []
    n = len(base)
    if count + n >= k:
        ans = base[k - count - 1]
        return ans

    for x in base:
        count += 1
        p = x % 10
        x *= 10
        a = x + p - 1
        b = a + 1
        c = b + 1
        n = 3
        if p == 0:
            n -= 1
            nx.extend([b, c])
        elif p == 9:
            n -= 1
            nx.extend([a, b])
        else:
            nx.extend([a, b, c])

    return LunLun(k, count, nx)


def main():
    k = int(eval(input()))
    base = list(range(1, 10))
    ans = LunLun(k, 0, base)
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
def LunLun(k, count, base):
    nx = []
    n = len(base)
    if count + n >= k:
        ans = base[k - count - 1]
        print(ans)
        exit()

    for x in base:
        count += 1
        p = x % 10
        x *= 10
        a = x + p - 1
        b = a + 1
        c = b + 1
        n = 3
        if p == 0:
            n -= 1
            nx.extend([b, c])
        elif p == 9:
            n -= 1
            nx.extend([a, b])
        else:
            nx.extend([a, b, c])

    return LunLun(k, count, nx)


def main():
    k = int(eval(input()))
    base = list(range(1, 10))
    LunLun(k, 0, base)
    

if __name__ == '__main__':
    main()
# Original solution
# coding: utf-8
# Your code here!
from collections import deque
k=int(eval(input()))
ans=[]
d=deque([1,2,3,4,5,6,7,8,9])
c=0
while c<11:
    q=d.popleft()
    ans.append(q)
    c=len(str(q))
    b=q%10
    if b!=0:
        d.append(q*10+b-1)
    d.append(q*10+b)
    if b!=9:
        d.append(q*10+b+1)
    
print((ans[k-1]))

# Optimized solution
# coding: utf-8
# Your code here!
from collections import deque
k=int(eval(input()))
ans=[]
d=deque([1,2,3,4,5,6,7,8,9])
c=0
while c<100100:
    q=d.popleft()
    ans.append(q)
    c+=1
    b=q%10
    if b!=0:
        d.append(q*10+b-1)
    d.append(q*10+b)
    if b!=9:
        d.append(q*10+b+1)
    
print((ans[k-1]))
# Original solution
n=int(eval(input()))
if n<10: print(n); exit()
l=[[[] for _ in range(10)] for _ in range(10)]
l[0]=[[i] for i in range(10)]
c=9
for i in range(9):
  for j in range(10):
    for k in (-1,0,1):
      if 0<=j+k<=9:
        for h in l[i][j+k]:
          if j: c+=1
          t=j*10**(i+1)+h
          l[i+1][j]+=[t]
          if c==n: print(t); exit()

# Optimized solution
n=int(eval(input()))
if n<10: print(n); exit()
r=range
l=[[[] for _ in r(10)] for _ in r(10)]
l[0]=[[i] for i in r(10)]
c=9
for i in r(9):
  for j in r(10):
    for k in r(-1,2):
      if 0<=j+k<=9:
        for h in l[i][j+k]:
          if j: c+=1
          t=j*10**(i+1)+h
          l[i+1][j]+=[t]
          if c==n: print(t); exit()
# Original solution
from collections import *
k=int(eval(input()));q=deque(list(range(1,10)));c=0
while c<k:
  t=q.popleft()
  for j in range(max(t%10-1,0),min(t%10+2,10)): q+=[t*10+j]
  c+=1
print(t)

# Optimized solution
k=int(eval(input()));l=list(range(1,10))
for i in l:
  if len(l)>k: break
  for j in range(max(i%10-1,0),min(i%10+2,10)): l.append(i*10+j)
print((l[k-1]))
# Original solution
k = int(eval(input()))
lunlun = list(range(1, 10))

for i in range(k - 1):
    a = lunlun[i]
    b = a * 10 + a % 10
    if a % 10 != 0:
        lunlun.append(b - 1)
    lunlun.append(b)
    if a % 10 != 9:
        lunlun.append(b + 1)
print((lunlun[k - 1]))

# Optimized solution
k = int(eval(input()))
li = [i + 1 for i in range(9)]

c = 0
while len(li) < k:
    if li[c] % 10 != 0:
        li.append(li[c] * 10 + li[c] % 10 - 1)
    li.append(li[c] * 10 + li[c] % 10)
    if li[c] % 10 != 9:
        li.append(li[c] * 10 + li[c] % 10 + 1)
    c += 1
print((li[k - 1]))
# Original solution
k = int(eval(input()))
cnt = 1
loop = 1
r_li = []

# 一桁小さいるんるんリストから次のるんるんリストを作成
def make_runrun(i, runrun_list):
    new_list = []
    for runrun in runrun_list:
        new_list.append('{}{}'.format(i, runrun))
    return new_list

tmp = [[str(i)] for i in range(10)]
r_li = [str(i) for i in range(1, 10)]

# 桁数ごとにループ
while len(r_li) < k:
    # 一桁小さいルンルン数のリスト
    next_tmp = [[]] * 10
    for i in range(1, 10):
        l = 0
        r_li.extend(make_runrun(i, tmp[i - 1]))
        l += len(tmp[i - 1])
        r_li.extend(make_runrun(i, tmp[i]))
        l += len(tmp[i])
        if i != 9:
            r_li.extend(make_runrun(i, tmp[i + 1]))
            l += len(tmp[i + 1])
        next_tmp[i] = r_li[-l:]
    for i in tmp[0]:
        next_tmp[0].append('{}{}'.format(0, i))
    for i in tmp[1]:
        next_tmp[0].append('{}{}'.format(0, i))
    tmp = next_tmp

print((r_li[k - 1]))

# Optimized solution
from collections import deque
k = int(eval(input()))
lunlun = deque([])
ans = 0

# 一桁のルンルン数
for i in range(1, 10):
    lunlun.append(str(i))
if k < 10:
    ans = lunlun[k - 1]

# 二桁以上のルンルン数
cnt = 9
while cnt < k + 1:
    # 1番小さなルンルン数を抜き出す
    l = lunlun.popleft()
    l_last = int(l[-1])
    if l_last != 0:
        lunlun.append('{}{}'.format(l, l_last - 1))
        cnt += 1
        if cnt == k:
            ans = lunlun[-1]
            break
    lunlun.append('{}{}'.format(l, l_last))
    cnt += 1
    if cnt == k:
        ans = lunlun[-1]
        break
    if l_last != 9:
        lunlun.append('{}{}'.format(l, l_last + 1))
        cnt += 1
        if cnt == k:
            ans = lunlun[-1]
            break

print(ans)
# Original solution
def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam)-1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam)-1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam)-1])
            nextNumList = [nextNum-1, nextNum, nextNum+1]
        
        for item in nextNumList:
            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            if myTupp[2] == 'e':
                return myTupp
        
        return myTupp
    
    else:
        lunlunCount += 1
        state = 'c'

        if lunlunCount == lunlun:
            state = 'e'
            print(inParam)

        return (lunlunCount, inParam, state)

K = int(eval(input()))

mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        # if mylunlun == K:
        #     break
    
    if mylunlun >= K:
        break

    mydigits += 1


# Optimized solution
K = int(eval(input()))

if K <= 9:
    print(K)
else:
    mylun = 9
    lunList = []

    for indx in range(1, 10):
        lunList.append(str(indx))

    while mylun < K:
        newLunList = []
        for lunItem in lunList:
            if lunItem[len(lunItem)-1] != "0":
                mylun += 1
                newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))
                if mylun == K:
                    print((lunItem + str( int(lunItem[len(lunItem)-1])-1 )))
                    break
            
            mylun += 1
            newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1]) ))
            if mylun == K:
                print((lunItem + str( int(lunItem[len(lunItem)-1]) )))
                break

            if lunItem[len(lunItem)-1] != "9":
                mylun += 1
                newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))
                if mylun == K:
                    print((lunItem + str( int(lunItem[len(lunItem)-1])+1 )))
                    break
        
        lunList = newLunList
# Original solution
k=int(eval(input()))
cand=[[1,2,3,4,5,6,7,8,9]]
for _ in range(9):
    tmp=[]
    for val in cand[-1]:
        s=str(val)
        if s[-1]=='0':
            tmp.append(val*10)
            tmp.append(val*10+1)
        elif s[-1]=='9':
            tmp.append(val*10+8)
            tmp.append(val*10+9)
        else:
            tmp.append(val*10+(int(s[-1])-1))
            tmp.append(val*10+(int(s[-1])))
            tmp.append(val*10+(int(s[-1])+1))
    cand.append(tmp)
ans=[]
for i in range(len(cand)):
    for val in cand[i]:
        ans.append(val)
ans=sorted(ans)
print((ans[k-1]))

# Optimized solution
k=int(eval(input()))
cand=[[1,2,3,4,5,6,7,8,9]]
for _ in range(9):
  tmp=[]
  for val in cand[-1]:
    if val%10!=0:
      tmp.append(val*10+(val%10-1))
    tmp.append(val*10+(val%10))
    if val%10!=9:
      tmp.append(val*10+(val%10+1))
  cand.append(tmp)
ans=[]
for i in range(len(cand)):
  for val in cand[i]:
    ans.append(val)
ans=sorted(ans)
print((ans[k-1]))
# Original solution
import queue
k = int(eval(input()))
q = queue.Queue()

for i in range(1,10):
    q.put(i)

for i in range(k):
    x = q.get()
    if not x%10 == 0:
        q.put(10*x+(x%10)-1)
    q.put(10*x+(x%10))
    if not x%10 == 9:
        q.put(10*x+(x%10)+1)

print(x)


# Optimized solution
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    k = int(ipt())
    q = queue.Queue()
    for i in range(1,10):
        q.put(i)
    for _ in [0]*k:
        qi = q.get()
        if not qi%10 == 0:
            q.put(qi*10+qi%10-1)
        q.put(qi*10+qi%10)
        if not qi%10 == 9:
            q.put(qi*10+qi%10+1)
    print(qi)
    return

if __name__ == '__main__':
    main()
# Original solution
import collections


def go_next(digits):
    if all(x==9 for x in digits):
        return [0]*len(digits) + [1]

    digits[0] += 1

    maxInc = -1
    # print(digits)
    for i in range(1, len(digits)):
        if digits[i-1] >= 10 or abs(digits[i]-digits[i-1]) >= 2:
            digits[i] += 1
            maxInc = i
        else:
            break
    # print(digits)
    if maxInc > 0:
        for i in range(maxInc, 0, -1):
            digits[i-1] = max(0, digits[i]-1)
    return digits


# go_next([9,8])


def main():
    K = int(eval(input()))

    digits = [0]
    for _ in range(K):
        digits = go_next(digits)

    print(("".join(map(str, reversed(digits)))))


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    from collections import deque

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


if __name__ == '__main__':
    main()
# Original solution
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

lunlun=deque()

def dfs(now):
    if len(now)>10:return
    lunlun.append(int(now))
    l=now[-1]
    
    if l!="0":
        dfs(now+str(int(l)-1))
    if l!="9":
        dfs(now+str(int(l)+1))
    dfs(now+l)

k=int(input().rstrip())
for i in range(1,10):
    dfs(str(i))


print((sorted(lunlun)[k-1]))

# Optimized solution
import sys
from collections import deque
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    k=int(input().rstrip())
    lunlun=deque([str(i) for i in range(1,10)])
    for _ in range(k-1):
        now=lunlun.popleft()
        last=now[-1]
        if last!="0":
            lunlun.append(now+str(int(last)-1))
        lunlun.append(now+last)
        if last!="9":
            lunlun.append(now+str(int(last)+1))
        
    print((lunlun[0]))

if __name__=="__main__":
    main()
# Original solution
import sys
input = sys.stdin.readline
import itertools

lunlun = [[] for i in range(11)]

def main():
    n = int(eval(input()))
    for i in range(100):
        flag = True
        l = len(str(i))
        if l == 1:
            lunlun[l - 1].append(i)
        else:
            for a in range(1, len(str(i))):
                if abs(int(str(i)[a - 1]) - int(str(i)[a])) >= 2:
                    flag = False
                    break
            if flag:
                lunlun[l - 1].append(i)
            else:
                continue
    for j in range(1, 9):
        for a in lunlun[j]:
            for b in range(10):
                if abs(int(str(a)[-1]) - b) < 2:
                    lunlun[j+1].append(int(str(a)+str(b)))
    lunlun2 = list(itertools.chain.from_iterable(lunlun))
    print((lunlun2[n]))

if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline


def main():
    n = int(eval(input()))
    lunlun = [[] for i in range(11)]
    lunlun[0] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    cnt = 9
    if n < 10:
        print(n)
        exit()
    for j in range(0, 10):
        for a in lunlun[j]:
            for b in range(10):
                if abs((a % 10) - b) < 2:
                    lunlun[j + 1].append(10 * a + b)
                    cnt += 1
                    if cnt == n:
                        print((10 * a + b))
                        exit()

if __name__ == '__main__':
    main()
# Original solution
import queue
k = int(eval(input()))

q = queue.Queue()
num = 0
for i in range(1,10):
    q.put(i)

while num<k:
    i = q.get()
    l = i%10
    if l!=0:
        q.put(i*10+l-1)
    q.put(i*10+l)
    if l!=9:
        q.put(i*10+l+1)
    num += 1

print(i)


# Optimized solution
k = int(eval(input()))

lst = [1,2,3,4,5,6,7,8,9]
count = 0

for i in range(k):
    num = lst[count]
    if num%10!=0:
        lst.append(num*10+num%10-1)
    lst.append(num*10+num%10)
    if num%10!=9:
        lst.append(num*10+num%10+1)
    count += 1

print((lst[k-1]))
# Original solution
from collections import deque

K = int(eval(input()))
dque = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

ans = 0
while True:
    v = dque.popleft()
    ans += 1
    if ans == K:
        print(v)
        exit(0)

    strv = str(v)
    if strv[-1] == '0':
        dque.append(int(strv+'0'))
        dque.append(int(strv+'1'))
    elif strv[-1] == '9':
        dque.append(int(strv+'8'))
        dque.append(int(strv+'9'))
    else:
        endv = int(strv[-1])
        dque.append(int(strv+str(endv-1)))
        dque.append(int(strv+str(endv)))
        dque.append(int(strv+str(endv+1)))


# Optimized solution
from collections import deque

K = int(eval(input()))
dque = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

ans = 0
while True:
    v = dque.popleft()
    ans += 1
    if ans == K:
        print(v)
        exit(0)

    for i in range(-1, 2):
        # 10で割った余りを取得して、iを足す
        tmp = v % 10+i
        if not(0 <= tmp <= 9):
            continue
        dque.append(v*10+tmp)
# Original solution

import copy

k = int(eval(input()))

lun = [1,2,3,4,5,6,7,8,9]
tlun = []
tlun = copy.deepcopy(lun)
length = 2
while len(lun) < k:
    tmp = []
    for x in tlun:
        y = str(x)
        xt = int( y[-1] )
        a = xt + 1
        b = xt - 1
        if a != 10:
            lun.append(int(y+str(a)))
            tmp.append(int(y+str(a)))
        
        if b != -1:
            lun.append(int(y+str(b)))
            tmp.append(int(y+str(b)))
        
        lun.append(int(y+str(xt)))
        tmp.append(int(y+str(xt)))
    tlun = copy.deepcopy(tmp)

lun.sort()
print((lun[k-1]))
        

    






# Optimized solution

import copy

k = int(eval(input()))

lun = [1,2,3,4,5,6,7,8,9]
tlun = []
tlun = copy.deepcopy(lun)
length = 2
while len(lun) < k:
    tmp = []
    for x in tlun:
        y = str(x)
        xt = int( y[-1] )
        a = xt + 1
        b = xt - 1
        if b != -1:
            lun.append(int(y+str(b)))
            tmp.append(int(y+str(b)))
        
        lun.append(int(y+str(xt)))
        tmp.append(int(y+str(xt)))

        if a != 10:
            lun.append(int(y+str(a)))
            tmp.append(int(y+str(a)))
        

    tlun = copy.deepcopy(tmp)

# lun.sort()
print((lun[k-1]))