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

def cal():
    count = 9
    d = [[1,2,3,4,5,6,7,8,9]]
    for i in range(10**9):
        d_ = []
        for j in range(len(d[i])):
            a = str(d[i][j])
            if a[-1]=="0":
                for k in [0, 1]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print((d_[-1]))
                        return
            elif a[-1]=="9":
                for k in [8, 9]:
                    d_.append(int(a)*10+k)
                    count += 1
                    if K == count:
                        print((d_[-1]))
                        return 
            else:
                for k in [-1, 0, 1]:
                    d_.append(int(a)*10+int(a[-1])+k)
                    count += 1
                    if K == count:
                        print((d_[-1]))
                        return
        d.append(d_)
if K <= 9:
    print(K)
else:
    cal()

# Optimized solution
from collections import deque
k = int(eval(input()))
if k <= 9: print(k)
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
count = 9
while count <= k:
    X = que.popleft()
    if X%10==0: check=[0, 1]
    elif X%10==9: check=[8, 9]
    else: check = [X%10-1, X%10, X%10+1]
    for i in check:
        que.append(X*10+i)
        count += 1
        if count == k:
            print((que[-1]))
            exit()
# Original solution
from collections import deque

def main():
    K = int(eval(input()))
    num_list = list(range(0, 10))
    def bfs():
        q = deque(list(map(str, num_list)))
        
        while len(num_list) < 2 * 10**6:
            now_str = q.popleft()
            now = int(now_str[0])
            for j in [now-1, now, now+1]:
                if j not in [-1, 10]:
                    new = str(j) + now_str
                    q.append(new)
                    if j != 0:
                        num_list.append(int(new))
    
    bfs()
    print((sorted(set(num_list))[K]))
            
if __name__ == "__main__":
    main()

# Optimized solution
from collections import deque

def main():
    K = int(eval(input()))
    
    # bfs
    count = 0
    q = deque(list(range(1, 10)))
    while count < K-1:
        now = q.popleft()
        count += 1

        d1 = now % 10
        base = 10 * now
        for suffix in [d1 - 1, d1, d1 + 1]:
            if suffix not in [-1, 10]:
                new = base + suffix
                q.append(new)

    ans = q.popleft()
    print(ans)
    

if __name__ == "__main__":
    main()
# Original solution
from collections import deque

def main():
    K = int(eval(input()))
    
    # bfs
    count = 0
    q = deque(list(range(1, 10)))
    while count < K-1:
        now = q.popleft()
        count += 1

        d1 = now % 10
        base = 10 * now
        for suffix in [d1 - 1, d1, d1 + 1]:
            if suffix not in [-1, 10]:
                new = base + suffix
                q.append(new)

    ans = q.popleft()
    print(ans)
    

if __name__ == "__main__":
    main()

# Optimized solution
from collections import deque

def main():
    K = int(eval(input()))
    
    # bfs
    q = deque(list(range(1, 10)))
    for _  in range(K-1):
        now = q.popleft()
        d1 = now % 10
        base = 10 * now
        
        for suffix in [d1 - 1, d1, d1 + 1]:
            if suffix not in [-1, 10]:
                new = base + suffix
                q.append(new)

    ans = q.popleft()
    print(ans)
    

if __name__ == "__main__":
    main()
# Original solution
import queue
K = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
for _ in range(K):
    x = q.get()
    d = x%10
    t = x*10
    if d != 0:
        q.put(t-1+d)
    q.put(t+d)
    if d != 9:
        q.put(t+1+d)
print(x)

# Optimized solution
# coding: utf-8
# d 現在の桁
# val 現在の値
# all 格納
def rec(d, val, all):
    # 格納
    all.append(val)
    # 10桁なら終了
    if d == 10:
        return
    # 再帰
    for i in range(-1, 2):
        add = val%10 + i
        if 0 <= add <= 9:
            rec(d+1, val*10+add, all)

# main
K = int(eval(input()))
all = []

# 1~9までを格納＆処理
for i in range(1, 10):
    rec(1, i, all)

all.sort()
print((all[K-1]))
# Original solution
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

sys.setrecursionlimit(10**7)

k = int(eval(input()))
data = [1,2,3,4,5,6,7,8,9]
def dfs(prenum,numberstr):
  if int(numberstr) > 3234566667:return
  if prenum - 1 >= 0:
    data.append(int(numberstr+str(prenum-1)))
    dfs(prenum-1,numberstr+str(prenum-1))
  data.append(int(numberstr+str(prenum)))
  dfs(prenum,numberstr+str(prenum))
  if prenum +1 <= 9:
    data.append(int(numberstr+str(prenum+1)))
    dfs(prenum+1,numberstr+str(prenum+1))
for i in range(1,10):
  dfs(i,str(i))
data.sort()
print((data[k-1]))
# print(data[:20])
# print(len(data))

# Optimized solution
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**7)

k = int(eval(input()))
ans = []
def dfs(string):
  if int(string) > 3234566667: return
  ans.append(int(string))
  botom = string[-1]
  intbotom = int(botom)
  if 0 <= intbotom -1 :
    dfs(string + str(intbotom-1))
  dfs(string+botom)
  if intbotom + 1 <= 9:
    dfs(string + str(intbotom+1))
for i in range(1,10):
  dfs(str(i))
ans .sort()

print((ans[k-1]))
# Original solution
K = int(eval(input()))
queue = []
for i in range(1, 10):
  queue.append(i)

while K != 0:
  if K <= len(queue):
    print((queue[K-1]))
    exit(0)

  K -= 1
  num = queue.pop(0)

  if K == 0:
    print(num)
    exit(0)

  o = int(str(num)[-1])
  for n in [o-1, o, o+1]:
    if n == -1 or n == 10: continue
    queue.append( int(str(num)+str(n)) )

# Optimized solution
from collections import deque

K = int(eval(input()))
queue = deque([i for i in range(1,10)])

while K != 0:
  if K <= len(queue):
    print((queue[K-1]))
    exit(0)

  K -= 1
  num = queue.popleft()

  o = int(str(num)[-1])
  for n in [o-1, o, o+1]:
    if n == -1 or n == 10: continue
    queue.append( int(str(num)+str(n)) )
# Original solution
#coding:utf-8

def up(nums):
    if len(nums) == nums.count(9):
        nums = [1] + [0] * len(nums)
        return nums
    
    for i in list(reversed(list(range(len(nums))))):
        if nums[i] > nums[i-1] or nums[i] == 9:
            continue
        else:
            nums[i] += 1
            for j in range(i+1, len(nums)):
                if j == len(nums) - 1:
                    nums[j] = max(nums[j-1]-1, 0)
                else:
                    nums[j] = max(nums[j-1] - 1, 0)
            return nums
          
  
def main():
    k = int(eval(input()))
    if k < 10:
        print(k)
        return
    cnt = 11
    nums = [1, 0]
    while cnt <= k:
        cnt += 1
        nums = up(nums)
        #print(nums)
        
    print((''.join([str(num) for num in nums])))
        
    
        
  
if __name__ == '__main__':
    main()

# Optimized solution
#coding:utf-8

def up(nums):
    if len(nums) == nums.count(9):
        nums = [1] + [0] * len(nums)
        return nums
    
    for i in list(reversed(list(range(len(nums))))):
        if nums[i] > nums[i-1] or nums[i] == 9:
            continue
        else:
            nums[i] += 1
            for j in range(i+1, len(nums)):
                nums[j] = max(nums[j-1]-1, 0)
            return nums
          
  
def main():
    k = int(eval(input()))
    nums = [0]
    for _ in range(k):
        nums = up(nums)
        
    print((''.join([str(num) for num in nums])))
        
    
        
  
if __name__ == '__main__':
    main()
# Original solution
from sys import stdin
import heapq
def main():

    input = stdin.readline

    K = int(eval(input()))

    h = []
    
    for i in range(1,10):
        heapq.heappush(h,i)
    
    for i in range(K):
        ans = heapq.heappop(h)

        if ans % 10 != 0:
            heapq.heappush(h,ans * 10 + (ans % 10 - 1))
        heapq.heappush(h,ans*10 + (ans%10))
        if ans % 10 != 9:
            heapq.heappush(h,ans * 10 + (ans % 10 + 1))
    
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
from sys import stdin
import heapq
def main():

    input = stdin.readline

    K = int(eval(input()))

    h = []

    for i in range(1,10):
        h.append(i)
    
    for i in range(K):
        ans = h[i]

        if ans % 10 != 0:
            h.append(ans * 10 + (ans % 10 - 1))
        h.append(ans*10 + (ans%10))
        if ans % 10 != 9:
            h.append(ans * 10 + (ans % 10 + 1))
    
    print(ans)

    # for i in range(1,10):
    #     heapq.heappush(h,i)
    
    # for i in range(K):
    #     ans = heapq.heappop(h)

    #     if ans % 10 != 0:
    #         heapq.heappush(h,ans * 10 + (ans % 10 - 1))
    #     heapq.heappush(h,ans*10 + (ans%10))
    #     if ans % 10 != 9:
    #         heapq.heappush(h,ans * 10 + (ans % 10 + 1))
    
    # print(ans)

if __name__ == "__main__":
    main()
# Original solution
import heapq
K = int(eval(input()))


def fun(h, n):
    tmp = str(n)
    if tmp[-1] == '0':
        heapq.heappush(h, int(tmp + '0'))
        heapq.heappush(h, int(tmp + '1'))
    elif tmp[-1] == '9':
        heapq.heappush(h, int(tmp + '8'))
        heapq.heappush(h, int(tmp + '9'))
    else:
        heapq.heappush(h, int(tmp + str(int(tmp[-1]) - 1)))
        heapq.heappush(h, int(tmp + tmp[-1]))
        heapq.heappush(h, int(tmp + str(int(tmp[-1]) + 1)))


h = list(range(1, 10))
while K > 0:
    tmp = heapq.heappop(h)
    fun(h, tmp)
    K -= 1
else:
    print(tmp)

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


def fun(h, n):
    tmp = n % 10
    if tmp != 0:
        heapq.heappush(h, 10 * n + tmp - 1)
    heapq.heappush(h, 10 * n + tmp)
    if tmp != 9:
        heapq.heappush(h, 10 * n + tmp + 1)


h = list(range(1, 10))
while K > 0:
    n = heapq.heappop(h)
    fun(h, n)
    K -= 1
else:
    print(n)
# Original solution
a={0}
_,*s=list(range(10))
while s:
  v=s.pop()
  a|={v}
  for w in range(max(0,v%10-1),min(10,v%10+2)):
    w+=v*10
    if w<4e9:s+=w,
print((sorted(a)[int(eval(input()))]))

# Optimized solution
_,*s=list(range(10))
for v in s:s+=[w+v*10for w in range(max(0,v%10-1),min(10,v%10+2))]*(v<4e8)
print((s[int(eval(input()))-1]))
# Original solution
import sys
sys.setrecursionlimit(10**7)
L = []
def lunlun(x, cnt, c):
  if cnt == 10:
    L.append(int(x))
    return
  e = int(x[-1])
  if c:
    for i in range(max(e-1, 0), min(e+2, 10)):
      lunlun(x+str(i), cnt+1, 1)
  else:
    lunlun(x+"0", cnt+1, 0)
    for i in range(1, 10):
      lunlun(x+str(i), cnt+1, 1)
lunlun("0", 1, 0)
for i in range(1, 10):
  lunlun(str(i), 1, 1)

k = int(eval(input()))
ans = L[k]
print(ans)

# Optimized solution
from collections import deque
que = deque()
L = []
k = int(eval(input()))
for i in range(1, 10):
  L.append(str(i))
  que.append(str(i))
while len(L) < k:
  top = que.popleft()
  e = int(top[-1])
  for i in range(max(e-1, 0), min(e+2, 10)):
    x = top + str(i)
    L.append(x)
    que.append(x)
ans = L[k-1]
print(ans)
# Original solution
from collections import deque
def main():
    q=deque()
    for i in range(1,10):
        q.append((str(i)))
    Ans=[]
    while q:
        s=q.popleft()
        if int(s)>3234566667:
            continue
        Ans.append(int(s))
        d=int(s[-1])
        if d==0:
            q.append(s+'0')
            q.append(s+'1')
        elif d==9:
            q.append(s+'8')
            q.append(s+'9')
        else:
            V=[d-1,d,d+1]
            for v in V:
                q.append(s+str(v))
    Ans.sort()
    #print(len(Ans))
    k=int(eval(input()))
    print((Ans[k-1]))
    
if __name__=='__main__':
    main()

# Optimized solution
from collections import deque
def main():
    k=int(eval(input()))
    if k<=9:
        return k
    q=deque()
    for i in range(1,10):
        q.append(i)
    Ans=list(range(1,10))
    cnt=9
    while cnt<k:
        s=q.popleft()
        d=s%10
        s*=10
        if d==0:
            q.append(s)
            q.append(s+1)
            Ans.append(s)
            Ans.append(s+1)
            cnt+=2
        elif d==9:
            q.append(s+8)
            q.append(s+9)
            Ans.append(s+8)
            Ans.append(s+9)
            cnt+=2
        else:
            V=[d-1,d,d+1]
            for v in V:
                q.append(s+v)
                Ans.append(s+v)
            cnt+=3
    return Ans[k-1]
    
if __name__=='__main__':
    print((main()))
# Original solution
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    nums = {0: [0, 1],
            1: [0, 1, 2],
            2: [1, 2, 3],
            3: [2, 3, 4],
            4: [3, 4, 5],
            5: [4, 5, 6],
            6: [5, 6, 7],
            7: [6, 7, 8],
            8: [7, 8, 9],
            9: [8, 9]}
    return nums[n]

K = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(int(str(now)[-1])):
        heappush(queue, int(str(now)+str(next_i)))

print((heappop(queue)))  # K 回目に取り出す最小値


# Optimized solution
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    nums = {0: [0, 1],
            1: [0, 1, 2],
            2: [1, 2, 3],
            3: [2, 3, 4],
            4: [3, 4, 5],
            5: [4, 5, 6],
            6: [5, 6, 7],
            7: [6, 7, 8],
            8: [7, 8, 9],
            9: [8, 9]}
    return nums[n]

K = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(now%10):
        heappush(queue, now*10 + next_i)

print((heappop(queue)))  # K 回目に取り出す最小値
# Original solution
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    nums = {0: [0, 1],
            1: [0, 1, 2],
            2: [1, 2, 3],
            3: [2, 3, 4],
            4: [3, 4, 5],
            5: [4, 5, 6],
            6: [5, 6, 7],
            7: [6, 7, 8],
            8: [7, 8, 9],
            9: [8, 9]}
    return nums[n]

K = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(now%10):
        heappush(queue, now*10 + next_i)

print((heappop(queue)))  # K 回目に取り出す最小値


# Optimized solution
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    nums = {0: [0, 1],
            1: [0, 1, 2],
            2: [1, 2, 3],
            3: [2, 3, 4],
            4: [3, 4, 5],
            5: [4, 5, 6],
            6: [5, 6, 7],
            7: [6, 7, 8],
            8: [7, 8, 9],
            9: [8, 9]}
    return nums[n]

K = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(now%10):
        heappush(queue, now*10 + next_i)

print((queue[0]))  # K 回目に取り出す最小値
# Original solution
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    nums = {0: [0, 1],
            1: [0, 1, 2],
            2: [1, 2, 3],
            3: [2, 3, 4],
            4: [3, 4, 5],
            5: [4, 5, 6],
            6: [5, 6, 7],
            7: [6, 7, 8],
            8: [7, 8, 9],
            9: [8, 9]}
    return nums[n]

K = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(now%10):
        heappush(queue, now*10 + next_i)

print((queue[0]))  # K 回目に取り出す最小値


# Optimized solution
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    if n == 0:
        return [0, 1]
    elif n == 9:
        return [8, 9]
    else:
        return [n-1, n, n+1]

K = int(eval(input()))
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(now%10):
        heappush(queue, now*10 + next_i)

print((queue[0]))  # K 回目に取り出す最小値
# Original solution
from heapq import heapify, heappush, heappop

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


K = int(eval(input()))

lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(lunlun)

for _ in range(K-1):
    now = heappop(lunlun)
    for i in next_num(int(str(now)[-1])):
        heappush(lunlun, now*10+i)

print((lunlun[0]))


# Optimized solution
from heapq import heapify, heappush, heappop

K = int(eval(input()))

ll = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(ll)

def next_num(X):
    n = int(str(X)[-1])
    if n == 0:
        return (0, 1)
    elif n == 9:
        return (8, 9)
    else:
        return (n-1, n, n+1)

for _ in range(K-1):
    lli = heappop(ll)
    next_nums = next_num(lli)
    for ni in next_nums:
        heappush(ll, lli*10+ni)

ans = ll[0]
print(ans)
# Original solution
k = int(eval(input()))

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

for i in lun_list:
    if str(i)[-1] == '0':
        for j in range(2):
            lun_list.append(int(str(i)+str(j)))
    elif str(i)[-1] == '9':
        for j in range(8,10):
            lun_list.append(int(str(i)+str(j)))
    else:
        for j in range(int(str(i)[-1])-1,int(str(i)[-1])+2):
            lun_list.append(int(str(i)+str(j)))
    if len(lun_list) > k:
        break

print((lun_list[k-1]))

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

num_list = [1,2,3,4,5,6,7,8,9]
num_a = ['0', '1']
num_b = ['8', '9']

for i in num_list:
    if str(i)[-1] == '0':
        for j in num_a:
            num_list.append(int(str(i)+j))
    elif str(i)[-1] == '9':
        for j in num_b:
            num_list.append(int(str(i)+j))
    else:
        num = int(str(i)[-1])
        for j in range(num-1, num+2):
            num_list.append(int(str(i)+str(j)))
    if len(num_list) > k:
        break

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

def main():

    k = int(eval(input()))
    cand = []
    for i in range(1, 10):
        cand.append(i)

    cnt = 0
    dq = deque()
    for i in range(1, 10):
        dq.append(i)

    while len(dq):
        v = dq.popleft()
        x = v%10 
        cnt += 1
        if x == 0:
            for j in (0, 1):
                nx = v*10 + j
                cand.append(nx)
                dq.append(nx)
        elif x == 9:
            for j in (-1, 0):
                nx = v*10 + 9 + j
                cand.append(nx) 
                dq.append(nx)
        else:
            for j in (-1, 0, 1):
                nx = v*10 + x + j
                cand.append(nx)
                dq.append(nx)
        if len(cand) > 2*k:
            break    

    cand.sort()
    print((cand[k-1]))
main()

# Optimized solution
#python3
from collections import deque

def main():

    k = int(eval(input()))
    cand = []
    for i in range(1, 10):
        cand.append(i)

    cnt = 0
    dq = deque()
    for i in range(1, 10):
        dq.append(i)

    while len(dq):
        v = dq.popleft()
        x = v%10 
        cnt += 1
        if x == 0:
            for j in (0, 1):
                nx = v*10 + j
                cand.append(nx)
                dq.append(nx)
        elif x == 9:
            for j in (-1, 0):
                nx = v*10 + 9 + j
                cand.append(nx) 
                dq.append(nx)
        else:
            for j in (-1, 0, 1):
                nx = v*10 + x + j
                cand.append(nx)
                dq.append(nx)
        if len(cand) > 2*k:
            break    

    print((cand[k-1]))
main()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque
cnt = 0
def main():
    K = int(readline())
    cnd = [i for i in range(1, 10)]

    dq = deque()
    for i in range(1, 10):
        dq.append(i)

    cnt = 0 
    while len(dq)>0:
        cnt += 1
        x = dq.popleft()
        v = x%10
        if v==0:
            for i in (0, 1):
                nx = 10*x+i
                cnd.append(nx)
                dq.append(nx)
        elif v == 9:
            for i in (-1, 0):
                nx = 10*x+9+i
                cnd.append(nx)
                dq.append(nx)
        else:
            for i in (-1, 0, 1):
                nx = 10*x+v+i
                cnd.append(nx)
                dq.append(nx)
        if cnt == K:
            break 
    cnd.sort()
    print((cnd[K-1]))
if __name__ == '__main__':
    main()


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
    K = int(readline())
    dq = []
    for i in range(1, 10):
        dq.append(i)
    for i in range(K):
        v = dq[i]
        r = v%10
        if r == 9:
            dq.append(v*10+8)
            dq.append(v*10+9)
        elif r == 0:
            dq.append(v*10)
            dq.append(v*10+1)
        else:
            dq.append(v*10+(r-1))
            dq.append(v*10+r)
            dq.append(v*10+(r+1))
    print((dq[K-1]))

if __name__ == '__main__':
    main()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
    K = int(readline())
    dq = []
    for i in range(1, 10):
        dq.append(i)
    for i in range(K):
        v = dq[i]
        r = v%10
        if r == 9:
            dq.append(v*10+8)
            dq.append(v*10+9)
        elif r == 0:
            dq.append(v*10)
            dq.append(v*10+1)
        else:
            dq.append(v*10+(r-1))
            dq.append(v*10+r)
            dq.append(v*10+(r+1))
    print((dq[K-1]))

if __name__ == '__main__':
    main()



# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque 
def main():
    K = int(readline())
    dq = deque() 
    cnd = []
    for i in range(1, 10):
        dq.append(i)
        cnd.append(i)
    
    while len(dq)>0:
        v = dq.popleft()
        r = v%10 
        if r == 0:
            nx = v*10
            dq.append(nx)
            cnd.append(nx)
            nx = v*10+1
            dq.append(nx)
            cnd.append(nx)
        elif r == 9:
            nx = v*10+8
            dq.append(nx)
            cnd.append(nx)
            nx = v*10+9
            dq.append(nx)
            cnd.append(nx)
        else:
            nx = v*10+(r-1)
            dq.append(nx)
            cnd.append(nx)
            nx = v*10+r
            dq.append(nx)
            cnd.append(nx)
            nx = v*10+(r+1)
            dq.append(nx)
            cnd.append(nx)
        if len(cnd) > K: 
            break
    print((cnd[K-1]))
if __name__ == '__main__':
    main()