CodeEff/ECCO huggingface dataset:
# Original solution
k = int(eval(input()))

lun_ls = []
def change_to_num(ls):
    ls = list(map(str, ls))
    strnum = ''.join(ls)
    return int(strnum)
def lun(num):
    '''
    渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出
    '''
    if num > 3234566667:
        return

    lun_ls.append(num)
    last = num % 10
    for nex in range(last-1, last+2):
        if 0<= nex < 10:
            new_str = str(num) + str(nex)
            new = int(new_str)
            lun(new)
            
for start in range(1,10):
    lun(start)
lun_ls.sort()
print((lun_ls[k-1]))

# Optimized solution
k = int(eval(input()))
# やっぱり一旦はglobalで書こ
total_ls = []
def dfs(A):
    if int(A) > 3234566667:
        return
    global total_ls
    total_ls.append(int(A))
    last = int(A[-1])
    if last == 0:
        nex = [1,0]
    elif last == 9:
        nex = [8,9]
    else:
        nex = [last-1,last,last+1]
    for n in nex:
        A += str(n)
        dfs(A)
        A = A[:-1]

for i in range(1,10):
    dfs(str(i))
total_ls.sort()
print((total_ls[k-1]))
# Original solution
k=int(eval(input()))
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

from collections import deque

q=deque([1,2,3,4,5,6,7,8,9])
ansl=[]
s=1
while len(str(s))<=10:
    s=q.popleft()
    ansl.append(s)
    sl=list(str(s))
    last_digit=int(sl[-1])
    for digit in range(max(0,last_digit-1),min(last_digit+1,9)+1):
        newval=int(str(s)+str(digit))
        #ansl.append(int(str(s)+str(digit)))
        q.append(newval)
print((ansl[k-1]))


# Optimized solution
k=int(eval(input()))
#n,p=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
#素因数分解した結果を2次元配列にして返す

all_list=[]

def rec(d,val):
    global all_list
    all_list.append(val)
    if d==10:
        return
    for j in range(-1,2,1):
        add=val%10+j
        if add>=0 and add<=9:
            rec(d+1,val*10+add)

for i in range(1,10):
    rec(1,i)
all_list.sort()
print((all_list[k-1]))
# Original solution
k = int(eval(input()))
l = set()


def construct(lunnum: str, depth: int, flag: bool):
    global l
    if depth == 0:
        l.add(int(lunnum))
        return
    m = int(lunnum[-1])
    for i in list(range(0, 10)) if flag else set([max(0, m - 1), m, min(9, m + 1)]):
        construct(lunnum + str(i), depth - 1, (i == 0) & flag)


construct("0", 10, True)
ls = sorted(list(l))
print((ls[k]))


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

# lunnum : 構築中のルンルン数
#  depth : 桁数
#   flag : 上位桁が全て0かどうかのフラグ
def construct(lunnum: str, depth: int, flag: bool):
    global l
    if depth == 0:
        l.add(int(lunnum))
        return
    # m = 末尾桁の値
    m = int(lunnum[-1])
    if flag:
        # 上位桁に0以外の数字が無いなら
        for i in range(0, 10):
            construct(lunnum + str(i), depth - 1, i == 0)
    else:
        # m=[1,8] は [m-1,m,m+1], m=0 は [0,1], m=9 は [8,9] を末尾にくっつけて再帰
        for i in set([max(0, m - 1), m, min(9, m + 1)]):
            construct(lunnum + str(i), depth - 1, False)


# サンプルケース(input=100000 output=3234566667)より、答えは10桁以下であるのでdepth=10としてDFS
construct("0", 10, True)
ls = sorted(list(l))
print((ls[k]))
# Original solution
k=int(eval(input()))

a=[]
for i in range(1,10):
    a.append(i)
while True:
    if k<=len(a):
        print((a[k-1]))
        break
    
    k-=len(a)
    old=[]
    old,a=a,old
    for x in old:
        for i in range(-1,2):
            d=x%10+i
            if d<0 or d>9:
                continue
            nx=x*10+d
            a.append(nx)
  

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

a=[i for i in range(1,10)]

for x in a:
    if k<=len(a):
        break
    
    if x%10!=0:
        a.append(10*x+(x%10)-1)
    a.append(10*x+(x%10))
    if x%10!=9:
        a.append(10*x+(x%10)+1)
        
print((a[k-1]))
# Original solution
import sys
from collections import deque
sys.setrecursionlimit(10**9)
 
K = int(eval(input()))
 
lis = deque()
def dfs(nowD, maxD, x):
    if nowD == maxD:
        lis.append(x)
        if len(lis) >= K:
            print((lis.pop()))
            exit()
    else:
        y = x%10
        x *= 10
        if y-1 >= 0:
            dfs(nowD+1, maxD, x+y-1)
        dfs(nowD+1, maxD, x+y)
        if y+1 <= 9:
            dfs(nowD+1, maxD, x+y+1)
 
for d in range(1, 11):
    for x in range(1, 10):
        dfs(1, d, x)

# Optimized solution
import sys
sys.setrecursionlimit(10**9)
 
K = int(eval(input()))
 
lis = []
def dfs(nowD, maxD, x):
    if nowD == maxD:
        lis.append(x)
        if len(lis) >= K:
            print((lis[K-1]))
            exit()
    else:
        y = x%10
        x *= 10
        if y-1 >= 0:
            dfs(nowD+1, maxD, x+y-1)
        dfs(nowD+1, maxD, x+y)
        if y+1 <= 9:
            dfs(nowD+1, maxD, x+y+1)
 
for d in range(1, 11):
    for x in range(1, 10):
        dfs(1, d, x)
# Original solution
import queue
n = int(eval(input()))
q = queue.Queue()
count=0
p=0
for i in range(1,10):
    q.put(i)
while count!=n:
    count+=1
    a = q.get()
    p = a
    str_a = str(a)
    if str_a[-1]=='0':
        q.put(a*10)
        q.put(a*10+1)
    elif str_a[-1]=='9':
        q.put(a*10+8)
        q.put(a*10+9)
    else:
        q.put(a*10 + int(str_a[-1])-1)
        q.put(a*10 + int(str_a[-1]))
        q.put(a*10 + int(str_a[-1])+1)
print(p)





# Optimized solution
import queue

k = int(eval(input()))
q = queue.Queue()

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

count = 0
while count < k:
    num = q.get()
    num_1 = int((str(num))[-1])
    if num_1 ==0:
        q.put(num*10)
        q.put(num*10+1)
    elif num_1==9:
        q.put(num*10+num_1-1)
        q.put(num*10+num_1)
    else:
        q.put(num*10+num_1-1)
        q.put(num*10+num_1)
        q.put(num*10+num_1+1)
    count+=1
    if k==count:
        ans = num
print(ans)
# Original solution
#!/usr/bin/env python3
def main():
    def rec(d: int, val: int, all: list):
        all.append(val)
        if d == 10:
            return
        for j in range(-1, 2):
            add = (val % 10) + j
            if add >= 0 and add <= 9:
                rec(d + 1, val * 10 + add, all)
    
    K = int(eval(input()))

    all = []
    for v in range(1, 10):
        rec(1, v, all)
    print((sorted(all)[K - 1]))


if __name__ == '__main__':
    main()


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

    K = int(eval(input()))
    q = deque()
    for i in range(1, 10):
        q.append(i)
    for i in range(K - 1):
        s = q.popleft()
        for j in range(-1, 2):
            add = (s % 10) + j
            if add >= 0 and add <= 9:
                q.append(s * 10 + add)
    print((q[0]))


main()
# Original solution
from collections import deque
K = int(eval(input()))
if K<10:
  print(K)
  exit()
  
q = deque([1,2,3,4,5,6,7,8,9])

cnt = 9
while q:
  n = q.popleft()
  r = n % 10
  n *= 10;
  for i in range(10):
    if abs(r - i) <= 1:
        q.append(n + i)
        cnt += 1
        if cnt == K:
          print((n+i))
          exit()

# Optimized solution
from collections import deque
k = int(eval(input()))

if k <= 9:
  print(k)
  exit()

que = deque([1,2,3,4,5,6,7,8,9])
cnt = len(que)
while cnt < k:
  x = que.popleft()
  m = x%10
  if m != 0:
    que.append(10*x+m-1)
    cnt+=1
    if cnt == k: print((que.pop())); exit();
  que.append(10*x+m)
  cnt+=1
  if cnt == k: print((que.pop())); exit();
  if m != 9:
    que.append(10*x+m+1)
    cnt+=1
    if cnt == k: print((que.pop())); exit();
# Original solution
from collections import deque
K = int(eval(input()))
q = deque([[1],[2],[3],[4],[5],[6],[7],[8],[9]])
cnt = 0
while cnt != K:
    nums = q.popleft()
    last = nums[-1]
    if last == 9:
        tmp = nums.copy()
        tmp.append(8)
        q.append(tmp)

        tmp = nums.copy()
        tmp.append(9)
        q.append(tmp)
    elif last == 0:
        tmp = nums.copy()
        tmp.append(0)
        q.append(tmp)

        tmp = nums.copy()
        tmp.append(1)
        q.append(tmp)
    else:
        tmp = nums.copy()
        tmp.append(last-1)
        q.append(tmp)

        tmp = nums.copy()
        tmp.append(last)
        q.append(tmp)

        tmp = nums.copy()
        tmp.append(last+1)
        q.append(tmp)

    cnt += 1
ans = 0
l = len(nums)
for i in range(l):
    ans += nums[i]*10**(l-i-1)
print(ans)

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

lunlun = [1,2,3,4,5,6,7,8,9]
p = 0

def lunlun_generator(now_lunlun):
    last = now_lunlun%10
    if last-1>=0:
        yield 10*now_lunlun+last-1
    yield 10*now_lunlun+last
    if last+1<=9:
        yield 10*now_lunlun+last+1 

while 1:
    for new_lunlun in lunlun_generator(lunlun[p]):
       lunlun.append(new_lunlun)

    p += 1
    if p == K:
        break

print((lunlun[p-1]))
# Original solution
k=int(eval(input()))
ans=[i for i in range(1,10)]
def dfs(x):
    if x>=3234566667:
        return
    for i in range(max(0,x%10-1),min(10,x%10+2)):
        ans.append(10*x+i)
        dfs(10*x+i)
for i in range(1,10):
    dfs(i)
print((sorted(ans)[k-1]))

# Optimized solution
k=int(eval(input()))
a=[]
def dfs(v):
    if v>3234566667:
        return
    a.append(v)
    for i in range(max(0,v%10-1),min(v%10+2,10)):
        dfs(10*v+i)
for i in range(1,10):
    dfs(i)
a.sort()
print((a[k-1]))
# Original solution
import sys
import heapq
def input(): return sys.stdin.readline().rstrip()

def main():
    K = int(eval(input()))
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    heapq.heapify(q)
    while len(q) < K:
        K -= len(q)
        new_q = []
        for i in q:
            d1 = int(str(i)[-1])
            if d1 > 0:
                new_q.append(i * 10 + d1 - 1)
            new_q.append(i * 10 + d1)
            if d1 < 9:
                new_q.append(i * 10 + d1 + 1)
        q = new_q
        heapq.heapify(q)
    print((q[K-1]))

if __name__ == '__main__':
    main()


# Optimized solution
import sys
import heapq
def input(): return sys.stdin.readline().rstrip()

def main():
    K = int(eval(input()))
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    heapq.heapify(q)
    while len(q) < K:
        K -= len(q)
        new_q = []
        for i in q:
            d1 = i % 10
            if d1 > 0:
                new_q.append(i * 10 + d1 - 1)
            new_q.append(i * 10 + d1)
            if d1 < 9:
                new_q.append(i * 10 + d1 + 1)
        q = new_q
        heapq.heapify(q)
    print((q[K-1]))

if __name__ == '__main__':
    main()
# Original solution
from collections import deque
k = int(eval(input()))
L = [1,2,3,4,5,6,7,8,9]
L = deque(L)
i = 0
while i < k:
    if int(str(L[i])[-1]) == 0:
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n2)
        L.append(n3)
    elif 1 <= int(str(L[i])[-1]) <= 8:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        n3 = L[i]*10 + L[i]%10 +1
        L.append(n1)
        L.append(n2)
        L.append(n3)
    elif int(str(L[i])[-1]) == 9:
        n1 = L[i]*10 + L[i]%10 -1
        n2 = L[i]*10 + L[i]%10
        L.append(n1)
        L.append(n2)
    i +=1

print((L[k-1]))


# Optimized solution
k = int(eval(input()))
L = []

def lunlun(d,v,L):
    L.append(v)
    if d == 10:
        return
    for i in range(-1,2):
        t = v%10 + i
        #print(v)
        if 0 <= t <=9:
            lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
    lunlun(1,v,L)
print((sorted(L)[k-1]))
# Original solution
k = int(eval(input()))
L = []

def lunlun(d,v,L):
    L.append(v)
    if d == 10:
        return
    for i in range(-1,2):
        t = v%10 + i
        #print(v)
        if 0 <= t <=9:
            lunlun(d+1,v*10+t,L)
#lunlun(1,1,L)
for v in range(1,10):
    lunlun(1,v,L)
print((sorted(L)[k-1]))

# Optimized solution
from collections import deque
K = int(eval(input()))

q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
q = deque(q)

def next_n(n):
    if n == 0:
        return [0, 1]
    elif n == 9:
        return [8, 9]
    else:
        return [n-1, n, n+1]

for _ in range(K-1):
    now = q.popleft()
    for next_ in next_n(now%10):
        q.append(now*10 + next_)

print((q[0]))
# Original solution
import sys
from string import digits

k = int(sys.stdin.readline().rstrip())

def main():
    if k <= 9:
        print(k)
        return
    res = list(digits[1:])
    r = k - 9
    nex = []
    while True:
        for n in res:
            o = ord(n[-1])
            for i in range(-1, 2):
                d = chr(o + i)
                if d < '0' or d > '9': continue
                nex.append(n + d)
                r -= 1
                if not r:
                    print((nex[-1]))
                    return
        res = nex.copy()
        nex.clear()

if __name__ ==  '__main__':
    main()

# Optimized solution
import sys

k = int(sys.stdin.readline().rstrip())

def main(k):
    if k <= 9:
        print(k)
        return
    res = list(range(1, 10))
    k -= 9
    while True:
        nex = []
        for n in res:
            r = n % 10
            n *= 10
            for i in range(-1, 2):
                if 0 <= r + i <= 9:
                    nex.append(n + r + i)
                    k -= 1
                    if not k:
                        print((nex[-1]))
                        return
        res = nex.copy()

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

K =int(eval(input()))

pque = []
for i in range(1, 10):
    heapq.heappush(pque, i)

for i in range(K):
    tmp = heapq.heappop(pque)
    if tmp % 10 == 0:
        heapq.heappush(pque, tmp * 10)
        heapq.heappush(pque, tmp * 10 + 1)
    elif tmp % 10 == 9:
        heapq.heappush(pque, tmp * 10 + 9)
        heapq.heappush(pque, tmp * 10 + 8)
    else:
        next_ = tmp % 10
        heapq.heappush(pque, tmp * 10 + next_ - 1)
        heapq.heappush(pque, tmp * 10 + next_)
        heapq.heappush(pque, tmp * 10 + next_ + 1)

print (tmp)
         
        
        

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

if K <= 9:
    print (K)
    exit()

lst = [[1] * 11 for _ in range(2)]
lst_append = lst.append
lst[0][10] = 0
lst[1][0] = 0
lst[1][10] = 0

now = 9
p = 0
flag = 0
while True:
    if p == 0:
        lst[flag + 1][0] = lst[flag][0] + lst[flag][1]
        p += 1
        continue
    tmp = lst[flag][p - 1] + lst[flag][p] + lst[flag][p + 1]
    lst[flag + 1][p] = tmp
    if now + tmp >= K:
        break
    now += tmp
    p += 1

    if p == 10:
        p = 0
        flag += 1
        lst_append([0] * 11)

# print ('now', now)
# print ('p', p)
# print ('flag', flag)
# print (lst[0])
# print (lst[1])

#先頭がpでかつ現在地がnow
ans = str(p)
flag += 1
while True:
    if flag == 0:
        break
    # print (p)
    if p >= 1 and K <= now + lst[flag - 1][p - 1]:
        flag -= 1
        ans += str(p - 1)
        p -= 1
    elif K <= now + lst[flag - 1][p - 1] + lst[flag - 1][p]:
        now += lst[flag - 1][p - 1]
        flag -= 1
        ans += str(p)
    else:
        now += lst[flag - 1][p - 1] + lst[flag - 1][p]
        flag -= 1
        ans += str(p + 1)
        p += 1

print (ans)

# for tmp in lst:
#     print (tmp)
# 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()
    a = x%10
    if a !=0:
        q.put(10*x +a -1)
    q.put(10*x +a )
    if a != 9:
        q.put(10*x +a +1)
print(x)

# Optimized solution
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    k = int(eval(input()))
    from collections import deque
    que = deque(list(range(1, 10)))
    for i in range(k):
        now = que.popleft()
        r = now%10
        nx = now*10
        if r == 0:
            for j in [0, 1]:
                que.append(nx+r+j)
        elif r == 9:
            for j in [-1, 0]:
                que.append(nx+r+j)
        else:
            for j in [-1, 0, 1]:
                que.append(nx+r+j)
    print(now)

if __name__ == '__main__':
    main()
# Original solution
k = int(eval(input()))
lunlun = []
def dfs(A):
    if len(A) > 10:
        return 
    else:
        num = A[-1]
        lunlun.append(int("".join(A)))
        if num == "0":
            for i in range(0, 2):
                A.append(str(i))
                dfs(A)
                A.pop()
        elif num == "9":
            for i in range(8, 10):
                A.append(str(i))
                dfs(A)
                A.pop()
        else:
            for i in range(int(num)-1, int(num)+2):
                A.append(str(i))
                dfs(A)
                A.pop()

for i in range(1, 10):
    dfs([str(i)])
lunlun.sort()
print((lunlun[k-1]))

# Optimized solution
k = int(eval(input()))
lunlun = []
def dfs(A):
    if len(A) > 10:
        return 
    else:
        num = int(A[-1])
        lunlun.append(int("".join(A)))
        if num == 0:
            for i in range(0, 2):
                A.append(str(i))
                dfs(A)
                A.pop()
        elif num == 9:
            for i in range(8, 10):
                A.append(str(i))
                dfs(A)
                A.pop()
        else:
            for i in range(num-1, num+2):
                A.append(str(i))
                dfs(A)
                A.pop()

for i in range(1, 10):
    dfs([str(i)])
lunlun.sort()
print((lunlun[k-1]))
# Original solution
k = int(eval(input()))

def hantei(n):
    string = str(n)
    length = len(string)
    ret = True
    for i in range(length-1):
        if abs(int(string[i]) - int(string[i+1])) > 1:
            ret = False
            break
    return ret

lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta = 2
while len(lst) < k+1:
    new = []
    for i in range(1, 10):
        tasu = i*(10**(keta-1))
        for j in sorted(dic.keys()):
            temp_lst = dic[j]
            bit = 0
            for youso in temp_lst:
                num = tasu + youso
                if hantei(num):
                    new.append(num)
                    bit = 1
                elif bit == 1:
                    break
    dic[keta] = new.copy()
    lst.extend(new)
    keta += 1

print((lst[k]))

# Optimized solution
from collections import deque

k = int(eval(input()))

if 1 <= k and k <= 9:
    print(k)
    exit()

d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
    num = d.popleft()
    if num % 10 != 0:
        new = 10*num + (num%10) - 1
        d.append(new)
        k -= 1
        if k == 0: break
    new = 10*num + (num%10)
    d.append(new)
    k -= 1
    if k == 0: break
    if num % 10 != 9:
        new = 10*num + (num%10) + 1
        d.append(new)
        k -= 1
        if k == 0: break

print(new)
# Original solution
from collections import deque

k = int(eval(input()))

if 1 <= k and k <= 9:
    print(k)
    exit()

d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
    num = d.popleft()
    if num % 10 != 0:
        new = 10*num + (num%10) - 1
        d.append(new)
        k -= 1
        if k == 0: break
    new = 10*num + (num%10)
    d.append(new)
    k -= 1
    if k == 0: break
    if num % 10 != 9:
        new = 10*num + (num%10) + 1
        d.append(new)
        k -= 1
        if k == 0: break

print(new)

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

if k <= 9:
    print(k)
k -= 9

lst = list(range(1, 10))
while k > 0:
    new = []
    for num in lst:
        amari = num % 10
        if amari == 0:
            new.append(num*10)
            new.append(num*10+1)
        elif amari == 9:
            new.append(num*10+8)
            new.append(num*10+9)
        else:
            new.append(num*10+(amari-1))
            new.append(num*10+amari)
            new.append(num*10+(amari+1))
    if len(new) >= k:
        print((new[k-1]))
        exit()
    else:
        k -= len(new)
        lst = new
# Original solution
from queue import Queue
k = int(eval(input()))
q = Queue()
Lunlun = []
for i in range(1, 10):
    q.put(i)
while True:
    if len(Lunlun) >= 10**5:
        break
    now = q.get()
    Lunlun.append(now)
    for i in range(-1, 2):
        if (now % 10) + i < 0 or 9 < (now % 10) + i:
            continue
        q.put(now*10 + (now % 10) + i)

print((Lunlun[k-1]))

# Optimized solution
import collections
# from queue import Queue
k = int(eval(input()))
q = collections.deque()
Lunlun = []
for i in range(1, 10):
    q.append(i)
while True:
    if len(Lunlun) >= 10**5:
        break
    now = q.popleft()
    Lunlun.append(now)
    for i in range(-1, 2):
        if (now % 10) + i < 0 or 9 < (now % 10) + i:
            continue
        q.append(now*10 + (now % 10) + i)

print((Lunlun[k-1]))
# Original solution
import queue

N = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
    q.put(i)

ans = 0
for i in range(N):
    ans = q.get()
    m = ans % 10
    if ans % 10 != 0:
        q.put(ans * 10 + m - 1)
    q.put(ans * 10 + m)
    if ans % 10 != 9:
        q.put(ans * 10 + m + 1)

print(ans)

# Optimized solution
import sys
sys.setrecursionlimit(10**6)

def dfs(n):
    if n > 3234566667:
        return
    ans.append(n)
    if n % 10 != 0:
        dfs(n * 10 + (n % 10) - 1)
    dfs(n * 10 + (n % 10))
    if n % 10 != 9:
        dfs(n * 10 + (n % 10) + 1)

N = int(eval(input()))
ans = []
for i in range(1, 10):
    dfs(i)
ans.sort()
print((ans[N - 1]))
# Original solution
def main():
    K = int(eval(input()))
    ans = set()

    def rec(S):
        if 3234566667 < int(S):
            return
        c = S[-1]
        d = int(c)
        for plus in range(d-1, d+2):
            if plus < 0:
                continue
            ans.add(int(S+str(plus)))
            rec(S+str(plus))

    for i in range(1, 10):
        ans.add(i)
        rec(str(i))

    ansc = ans.copy()
    for a in ansc:
        S = str(a)
        pre = ""
        for i, s in enumerate(S):
            if i == 0:
                pre = s
                continue
            if abs(int(pre) - int(s)) > 1:
                ans.discard(a)
                break
            pre = s
    answer = sorted(ans)
    print((answer[K-1]))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    K = int(eval(input()))
    LL = set()

    def dfs(s):
        if 3234566667 < int(s):
            return
        c = int(s[-1])
        for p in range(-1, 2):
            if c+p < 0 or 9 < c+p:
                continue
            LL.add(int(s+str(c+p)))
            dfs(s+str(c+p))

    for s in "123456789":
        LL.add(int(s))
        dfs(s)

    ans = sorted(LL)
    print((ans[K-1]))


if __name__ == '__main__':
    main()
# Original solution
import sys
k = int(eval(input()))
if k <= 9:
	print(k)
	sys.exit()

def judge(s):
	for i in range(1,len(s)):
		if abs(int(s[i-1]) - int(s[i])) > 1:
			return 0
	return 1

q = ['1','2','3','4','5','6','7','8','9']
cnt = 9
cond = False
while True:

	cp = q.pop(0)
	digit = int(cp[-1])
	for d in range(-1,2):
		if 0 <= digit + d <= 9:
			cnt += 1
			if cnt == k:
				ans = cp+str(digit+d)
				cond = True
				break
			q.append(cp+str(digit+d))
	
	if cond:
		break
print(ans)


# Optimized solution
import sys
from collections import deque
K = int(eval(input()))
if K <= 9:
	print(K)
	sys.exit()
q = deque(['1', '2','3','4','5','6','7','8','9'])
cnt = 0
while True:
	cp = q.popleft()
	cnt += 1
	if cnt == K:
		ans = int(cp)
		break
	r = int(cp[-1])
	for d in [-1,0,1]:
		dd = r + d
		if 0 <= dd < 10:
			q.append(cp + str(dd))

print(ans)