CodeEff/ECCO huggingface dataset:
# Original solution
from itertools import product

k = int(eval(input()))
ls = []

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

while len(ls) < k:
    for i in range(1, 10):
        for j in product([-1, 0, 1], repeat=digit):
            num = str(i)
            skip = 0
            for y in j:
                x = int(num[-1])+y
                if x < 0 or 9 < x:
                    skip = 1
                    break
                num += str(x)
            if skip:
                continue
            ls.append(int(num))
    digit += 1
print((ls[k-1]))

# Optimized solution
k = int(eval(input()))
ans = [i for i in range(1, 10)]


def generate_lunlun(x):
    y = x % 10
    if 0 <= y-1:
        yield 10*x + y-1
    yield 10*x + y
    if y+1 < 10:
        yield 10*x + y+1


idx = 0
while len(ans) < k:
    x = ans[idx]
    for i in generate_lunlun(x):
        ans.append(i)
    idx += 1

print((ans[k-1]))
# Original solution
k = int(eval(input()))
ans = []


def dfs(x):
    if x > 10**10:
        return 0
    else:
        ans.append(x)
        y = x % 10
        for i in range(10):
            if abs(y-i) <= 1:
                dfs(10*x+i)
                
for i in range(1, 10):
    dfs(i)
ans.sort()
print((ans[k-1]))

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


def dfs(x):
    if x > 3234566667:
        return 0
    else:
        ans.append(x)
        y = x % 10
        for i in range(10):
            if abs(y-i) <= 1:
                dfs(10*x+i)
    

for i in range(1, 10):
    dfs(i)
    
ans.sort()
print((ans[k-1]))
# Original solution
k = int(eval(input()))
li = [str(i) for i in range(1, 10)]
n = 0
while n < 9:
  rep = li[:]
  for r in rep:
    if r[-1] == "0":
      li.append(r+"0")
      li.append(r+"1")
    elif r[-1] == "9":
      li.append(r+"8")
      li.append(r+"9")
    else:
      x = int(r[-1])
      li.append(r+str(x-1))
      li.append(r+str(x))
      li.append(r+str(x+1))
  n += 1

setli = set(li)
li = list(setli)
#print(li)
intli = [int(i) for i in li]
intli.sort()
#print(intli)
#intli.sort
#print(len(intli))
#print(intli)
print((intli[k-1]))


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

def dfs(k):
  cnt = 0
  stack = deque()
  for i in range(1, 10):
    stack.append(i)
  while cnt <= k:
    q = stack.popleft()
    ans.append(q)
    cnt += 1
    l = q % 10
    for x in range(max(0, l - 1), min(10, l + 2)):
      stack.append(q * 10 + x)
          
ans = []
dfs(k)
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(1,k):
    l = q.get()
    m = l % 10
    if (m != 0):
        q.put(l * 10 + m - 1)
    q.put(l * 10 + m)
    if (m != 9):
        q.put(l * 10 + m + 1)

print((q.get())) 

# Optimized solution
from collections import deque

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

for i in range(1,k):
    l = q.popleft()
    if (len(q) < k):
        m = l % 10
        if (m != 0):
            q.append(l * 10 + m - 1)
        q.append(l * 10 + m)
        if (m != 9):
            q.append(l * 10 + m + 1)

print((q.popleft()))
# Original solution
N = int(eval(input()))
tmp = [i for i in range(1, 10)]
ans = list(tmp)
for i in range(10):
    tmp2 = []
    for x in tmp:
        k = int(str(x)[-1])
        if k != 0:
            ans.append(10*x-1 + k)
            tmp2.append(10*x-1 + k)
        if k != 9:
            tmp2.append(10*x+1 + k)
            ans.append(10*x+1 + k)
        tmp2.append(10*x + k)
        ans.append(10*x + k)
    tmp = list(tmp2)

ans.sort()
print((ans[N-1]))


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

q = collections.deque([i for i in range(1, 10)])
count = 0
while(q):
    count += 1
    x = q.popleft()
    if count == K:
        print(x)
        break
    if x % 10 != 0:
        q.append(x*10 + (x % 10 - 1))
    q.append(x*10 + (x % 10))
    if x % 10 != 9:
        q.append(x*10 + (x % 10 + 1))
# Original solution
K = int(eval(input()))
d = [1,2,3,4,5,6,7,8,9]

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

cnt = 9
while cnt < K:
  _ = d.pop(0)
  matsubi = _%10
  
  if matsubi == 0:
    d.append(_*10+matsubi)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()
    d.append(_*10+matsubi+1)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()
    
  elif matsubi == 9:
    d.append(_*10+matsubi-1)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()

    d.append(_*10+matsubi)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()
  else:
    d.append(_*10+matsubi-1)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()

    d.append(_*10+matsubi)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()

    d.append(_*10+matsubi+1)
    cnt += 1
    if cnt == K:
      print((d[-1]))
      exit()

# Optimized solution
K = int(eval(input()))
d = [1,2,3,4,5,6,7,8,9]

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

cnt = 9
while cnt < K:
  _ = d.pop(0)
  matsubi = _%10
  
  if matsubi == 0:
    d.append(_*10+matsubi)
    d.append(_*10+matsubi+1)
    cnt += 2

  elif matsubi == 9:
    d.append(_*10+matsubi-1)
    d.append(_*10+matsubi)
    cnt += 2

  else:
    d.append(_*10+matsubi-1)
    d.append(_*10+matsubi)
    d.append(_*10+matsubi+1)
    cnt += 3
      
ans = -1*(cnt - K + 1)
print((d[ans]))
# Original solution
k = int(eval(input()))

nums = []
def inc(num):
    if num > 3234566667:
        return None
    if num <= 3234566667:
      nums.append(num)

    num_str = str(num)
    end = num_str[-1:]
    end_num = int(end)

    if end_num < 9:
        inc(int(num_str + str(end_num + 1)))
   
    inc(int(num_str + end))
    
    if end_num > 0:
        inc(int(num_str + str(end_num - 1)))

for i in range(1, 10):
    inc(i)

sort_nums = sorted(nums)
print((sorted(nums)[k - 1]))

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

nums = []
def inc(num):
    if num > 3234566667:
        return None
    if num <= 3234566667:
      nums.append(num)

    end = str(num)[-1:]
    end_num = int(end)

    if end_num < 9:
        inc(num * 10 + end_num + 1)

    inc(num * 10 + end_num)

    if end_num > 0:
        inc(num * 10 + end_num - 1)

for i in range(1, 10):
    inc(i)

sort_nums = sorted(nums)
print((sorted(nums)[k - 1]))
# Original solution
z = int(eval(input()))
l = []
for i in range(1,10):
    l.append(i)
    for j in range(max(0,i-1),min(10,i+2)):
        l.append(int(str(i)+str(j)))
        for k in range(max(j-1,0),min(10,j+2)):
            l.append(int(str(i)+str(j)+str(k)))
            for m in range(max(k-1,0),min(10,k+2)):
                l.append(int(str(i)+str(j)+str(k)+str(m)))
                for n in range(max(m-1,0),min(10,m+2)):
                    l.append(int(str(i)+str(j)+str(k)+str(m)+str(n)))
                    for o in range(max(n-1,0),min(10,n+2)):
                        l.append(int(str(i)+str(j)+str(k)+str(m)+str(n)+str(o)))
                        for p in range(max(o-1,0),min(10,o+2)):
                            l.append(int(str(i)+str(j)+str(k)+str(m)+str(n)+str(o)+str(p)))
                            for q in range(max(p-1,0),min(10,p+2)):
                                l.append(int(str(i)+str(j)+str(k)+str(m)+str(n)+str(o)+str(p)+str(q)))
                                for r in range(max(q-1,0),min(10,q+2)):
                                    l.append(int(str(i)+str(j)+str(k)+str(m)+str(n)+str(o)+str(p)+str(q)+str(r)))
                                    for s in range(max(r-1,0),min(10,r+2)):
                                        l.append(int(str(i)+str(j)+str(k)+str(m)+str(n)+str(o)+str(p)+str(q)+str(r)+str(s)))

l.sort()
print((l[z-1]))

# Optimized solution
from collections import deque
k = int(eval(input()))
s = deque([1,2,3,4,5,6,7,8,9])
for i in range(k):
    c = s.popleft()
    d = int(str(c)[-1])
    for j in range(max(0,d-1),min(10,d+2)):
        s.append(int(str(c)+str(j)))
print(c)
# Original solution
from collections import deque
k = int(eval(input()))
Q = deque(list(range(1, 10)))
for _ in range(k):
  x = Q.popleft()
  y = x % 10
  z = 10*x + y
  if y != 0:
    Q += [z-1]
  Q += [z]
  if y != 9:
    Q += [z+1]
print(x)

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

Q = deque(list(range(1, 10))) #るんるん数を格納するキュー
# Q: 1 2 3 4 5 6 7 8 9

for i in range(k):
  x = Q.popleft()
  #x = 1 <--  Q: 2 3 4 5 6 7 8 9
  last_digit = x % 10 # 1 一番目の桁の値
  if last_digit == 0:
        Q.append(10*x + 0)
        Q.append(10*x + 1)

  elif last_digit == 9:
        Q.append(10*x + 8)
        Q.append(10*x + 9)

  else: # 1<=last_digit <=8
        Q.append(10*x + last_digit - 1)
        Q.append(10*x + last_digit)
        Q.append(10*x + last_digit + 1)
print(x)
# Original solution
from collections import deque
k = int(eval(input()))

Q = deque(list(range(1, 10))) #るんるん数を格納するキュー
# Q: 1 2 3 4 5 6 7 8 9

for i in range(k):
  x = Q.popleft()
  #x = 1 <--  Q: 2 3 4 5 6 7 8 9
  last_digit = x % 10 # 1 一番目の桁の値
  if last_digit == 0:
        Q.append(10*x + 0)
        Q.append(10*x + 1)

  elif last_digit == 9:
        Q.append(10*x + 8)
        Q.append(10*x + 9)

  else: # 1<=last_digit <=8
        Q.append(10*x + last_digit - 1)
        Q.append(10*x + last_digit)
        Q.append(10*x + last_digit + 1)
print(x)

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

Q = deque(list(range(1, 10))) #るんるん数を格納するキュー
# Q: 1 2 3 4 5 6 7 8 9

for i in range(k):
  x = Q.popleft()
  #x = 1 <--  Q: 2 3 4 5 6 7 8 9
  last_digit = x % 10 # 1 一番目の桁の値
  z = 10*x + last_digit #11

  if last_digit != 0:
    Q.append(z-1)
    # Q: 2 3 4 5 6 7 8 9 <--10
  Q.append(z)
  # Q: 2 3 4 5 6 7 8 9 10 <--11
  if last_digit != 9:
    Q.append(z+1)
    # Q: 2 3 4 5 6 7 8 9 10 11 <--12
print(x)
# Original solution
# 解説放送
k = int(eval(input()))
a = [i+1 for i in range(9)]


while 1:
    if k <= len(a):
        print((a[k-1]))
        exit()
    k -= len(a)
    old = []
    a, old = old, a
    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
# 解説PDF
from collections import deque

k = int(eval(input()))

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

for i in range(k-1):
    x = que.popleft()
    y = x % 10  
    if y != 0:
        que.append(10*x+y-1)
    que.append(10*x+y)
    if y != 9:
        que.append(10*x+y+1)

ans = que.popleft()
print(ans)
# Original solution
from collections import deque
k = int(eval(input()))
cnt = 0

q = deque()
for i in range(1, 10):
    q.append((str(i), i))
    cnt += 1
    if cnt == k:
        print((str(i)))
        exit()

while q:
    lun, num = q.popleft()

    for i in range(num - 1, num + 2):
        if i < 0 or i >9:continue
        temp = lun + str(i)
        q.append((temp, i))
        cnt += 1
        if cnt == k:
            print(temp)
            exit()

# Optimized solution
from collections import deque
def bfs(k):
    lunlun = []
    q = deque()
    count = 0
    for i in range(1, 10):
        lunlun.append(i)
        q.append(i)
        count += 1

    if count >= k:return lunlun[k - 1]

    while True:
        num = q.popleft()
        tail = num % 10
        for i in [-1, 0, 1]:
            temp = tail + i
            if temp == -1 or temp == 10:continue
            q.append(num * 10 + temp)
            lunlun.append(num * 10 + temp)
            count += 1
            if k == count:return lunlun[k - 1]

k = int(eval(input()))
print((bfs(k)))
# Original solution
from collections import deque
k = int(eval(input()))
d = deque([1,2,3,4,5,6,7,8,9])

ans = []
while len(ans) < k:
    a = d.popleft()
    ans.append(a)
    l = [a%10-1, a%10, a%10+1]
    for i in l:
        if i==-1 or i==10:
            continue
        d.append(a*10 + i)

print((ans[k-1]))

# Optimized solution
from collections import deque
k = int(eval(input()))
d = deque([1,2,3,4,5,6,7,8,9])

for i in range(k):
    a = d.popleft()
    l = [a%10-1, a%10, a%10+1]
    for j in l:
        if j==-1 or j==10:
            continue
        d.append(a*10 + j)

print(a)
# Original solution
def gen_lunlun(digit, li):
    if len(li) == digit:
        lunluns.append(''.join(map(str, li)))
        return
    min_num = max(0, li[-1] - 1)
    max_num = min(9, li[-1] + 1)
    for i in range(min_num, max_num + 1):
        gen_lunlun(digit, li + [i])


k = int(eval(input()))

lunluns = []
for d in range(1, 11):
    for i in range(1, 10):
        gen_lunlun(d, [i])
print((lunluns[k - 1]))


# Optimized solution
from collections import deque


def nth_ll(k):
    if k < 10:
        return k
    queue = deque([i for i in range(1, 10)])
    cnt = 9
    while True:
        n = queue.popleft()
        for i in range(-1 if n % 10 != 0 else 0, 2 if n % 10 != 9 else 1):
            queue.append(10 * n + n % 10 + i)
            cnt += 1
            if cnt == k:
                return queue.pop()

print((nth_ll(int(eval(input())))))
# Original solution
import sys

sys.setrecursionlimit(10 ** 5)


def dfs(v):
    ans.append(v)
    if v > 1_000_000_000:
        return
    for d in range(10):
        if abs(d - v % 10) <= 1:
            nv = v * 10 + d
            dfs(nv)


K = int(eval(input()))
ans = []
[dfs(i) for i in range(1, 10)]
print((sorted(ans)[K - 1]))


# Optimized solution
import sys

sys.setrecursionlimit(10 ** 5)


def dfs(v):
    if v > 3234566667:
        return
    ans.append(v)
    d = v % 10
    if d - 1 >= 0:
        dfs(v * 10 + d - 1)
    dfs(v * 10 + d)
    if d + 1 < 10:
        dfs(v * 10 + d + 1)


K = int(eval(input()))
ans = []
[dfs(i) for i in range(1, 10)]
print((sorted(ans)[K - 1]))
# Original solution
import sys

sys.setrecursionlimit(10 ** 5)


def dfs(v):
    if v > 3234566667:
        return
    ans.append(v)
    d = v % 10
    if d - 1 >= 0:
        dfs(v * 10 + d - 1)
    dfs(v * 10 + d)
    if d + 1 < 10:
        dfs(v * 10 + d + 1)


K = int(eval(input()))
ans = []
[dfs(i) for i in range(1, 10)]
print((sorted(ans)[K - 1]))


# Optimized solution
def is_good(mid, key):
    S = list(map(int, str(mid)))
    N = len(S)
    dp = [[[0] * 11 for _ in range(2)] for _ in range(N + 1)]
    dp[1][1][10] = 1
    for k in range(1, S[0]):
        dp[1][1][k] = 1
    dp[1][0][S[0]] = 1
    for i in range(1, N):
        for k in range(1, 11):
            dp[i + 1][1][k] += dp[i][0][10] + dp[i][1][10]
        for is_less in range(2):
            for k in range(10):
                for l in range(k - 1, k + 2):
                    if not 0 <= l <= 9 or (not is_less and l > S[i]):
                        continue
                    dp[i + 1][is_less or l < S[i]][l] += dp[i][is_less][k]
    return sum(dp[N][0][k] + dp[N][1][k] for k in range(10)) >= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


K = int(eval(input()))
print((binary_search(0, 3234566667, K)))
# Original solution
def is_lunlun(n):
    m = str(n)
    for i in range(1,len(m)):
        if abs(int(m[i]) - int(m[i-1])) > 1:
            return False
    return True

def main():
    K = int(eval(input()))
    A = [format(str(i),"0>5") for i in range(100000) if is_lunlun(i)]
    B = [int(a1+a2) for a1 in A for a2 in A if int(a1+a2) < 3234566668 and is_lunlun(int(a1+a2))]
    B2 = sorted(set(B))
    print((B2[K]))

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    K = int(eval(input()))
    from collections import deque
    A = deque([1,2,3,4,5,6,7,8,9])
    a = 0
    while True:
        x = A.popleft()
        xmod10 = x % 10
        if xmod10 != 0:
            A.append(10*x + xmod10 - 1)
        A.append(10*x + xmod10)
        if xmod10 != 9:
            A.append(10*x + xmod10 + 1)
        a += 1
        if a == K:
            print(x)
            break

if __name__ == "__main__":
    main()
# Original solution
import sys
from collections import deque
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(eval(input()))

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

K=II()
for i in range(K-1):
    v = deq.popleft()
    last = int(v[-1])
    if last == 0:
        deq.append(v + "0")
        deq.append(v + "1")
    elif last == 9:
        deq.append(v + "8")
        deq.append(v + "9")
    else:
        deq.append("{}{}".format(v, last-1))
        deq.append("{}{}".format(v, last))
        deq.append("{}{}".format(v, last+1))

print((deq.popleft()))


# Optimized solution
import sys
from collections import deque
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(eval(input()))

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

K=II()
for i in range(K-1):
    v = deq.popleft()
    last = v % 10
    if last == 0:
        deq.append(10*v)
        deq.append(10*v + 1)
    elif last == 9:
        deq.append(10*v + 8)
        deq.append(10*v + 9)
    else:
        deq.append(10*v + last-1)
        deq.append(10*v + last)
        deq.append(10*v + last+1)

print((deq.popleft()))
# Original solution
n=int(eval(input()))
import queue
q=queue.Queue()
for i in range(1,10):
    q.put(i)
while n!=1:
    x=q.get();k=x%10
    for j in [10*x+i for i in range(max(0,k-1),min(10,k+2))] :
        q.put(j)
    n-=1
print((q.get()))

# Optimized solution
n=int(eval(input()))
import queue
q=queue.Queue()
for i in range(1,10):
    q.put(i)
while n!=1:
    x=q.get();k=x%10
    for i in range(max(0,k-1),min(10,k+2)) :
        q.put(10*x+i)
    n-=1
print((q.get()))
# Original solution
K = int(eval(input()))
numbers = set([])
q = set(list(map(str, [1, 2, 3, 4, 5, 6, 7, 8, 9])))
# print(f'{q=}')

while len(numbers) <= 100000:  # 10**8:
    # print('test')
    qq = set([])
    for i in q:
        # print(f'{i=}')
        if len(i) == 1:
            if i == '0':
                n = i + '0'
                qq.add(n)
                n = i + '1'
                qq.add(n)
            elif i == '9':
                n = i + '9'
                qq.add(n)
                n = i + '8'
                qq.add(n)
            else:
                v = int(i)
                n = i + str(v - 1)
                qq.add(n)
                n = i + str(v)
                qq.add(n)
                n = i + str(v + 1)
                qq.add(n)
        else:
            if i[-1] == '0':
                n = i + '0'
                qq.add(n)
                n = i + '1'
                qq.add(n)
            elif i[-1] == '9':
                n = i + '9'
                qq.add(n)
                n = i + '8'
                qq.add(n)
            else:
                v = int(i[-1])
                n = i + str(v - 1)
                qq.add(n)
                n = i + str(v)
                qq.add(n)
                n = i + str(v + 1)
                qq.add(n)
    # print(f'{qq=}')
    numbers |= q
    # print(f'{numbers=}')
    # print(f'{len(numbers)=}')
    q = qq

numbers = sorted(map(int, numbers))
# print(f'{numbers[:30]=}')
ans = numbers[K - 1]
print(ans)


# Optimized solution
K = int(eval(input()))
numbers = set([])
q = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
# print(f'{q=}')

while len(numbers) <= 100000:  # 10**8:
    # print('test')
    qq = set([])
    for i in q:
        # print(f'{i=}')
        if i % 10 != 0:
            n = i * 10 + (i % 10) - 1
            qq.add(n)
        if i % 10 != 9:
            n = i * 10 + (i % 10) + 1
            qq.add(n)
        n = i * 10 + (i % 10)
        qq.add(n)
    numbers |= q
    # print(f'{numbers=}')
    # print(f'{len(numbers)=}')
    q = qq

numbers = sorted(map(int, numbers))
# print(f'{numbers[:30]=}')
ans = numbers[K - 1]
print(ans)
# Original solution
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def add_v(v):
  global cands
  global K
  v = str(v)
  v0 = int(v[-1])
  if v0 == 0:
    cands += [int(v+'0'), int(v+'1')]
    K -=2
  elif v0 == 9:
    cands += [int(v+'8'), int(v+'9')]
    K -= 2
  else:
    cands += [int(v+str(v0-1)), int(v+str(v0)), int(v+str(v0+1))]
    K -= 3

K = int(eval(input()))
idk = K
K -= 9
idx = 0
while K >= 0:
  add_v(cands[idx])
  idx += 1

print((cands[idk-1]))

# Optimized solution
cands = [1, 2, 3, 4, 5, 6, 7, 8, 9]

def add_v(v):
  global cands
  global K
  v0 = v % 10
  if v0 == 0:
    cands += [v*10, v*10+1]
    K -=2
  elif v0 == 9:
    cands += [v*10+8, v*10+9]
    K -= 2
  else:
    cands += [v*10+v0-1, v*10+v0, v*10+v0+1]
    K -= 3

K = int(eval(input()))
idk = K
K -= 9
idx = 0
while K >= 0:
  add_v(cands[idx])
  idx += 1

print((cands[idk-1]))
# Original solution
from collections import deque
li=[i for i in range(1,10)]
def bfs(K):
    d=deque()
    for i in range(1,10):
        d.append(str(i))
    while(len(li)<K):
        s=d[0]
        d.popleft()
        now=[int(s+s[-1])]
        if(s[-1]!='0'):
            now.append(int(s+str(int(s[-1])-1)))
        if(s[-1]!='9'):
            now.append(int(s+str(int(s[-1])+1)))
        now.sort()
        for i in range(len(now)):
            li.append(now[i])
            d.append(str(now[i]))
K=int(eval(input()))
bfs(K)
print((li[K-1]))

# Optimized solution
from collections import deque
lunlun=[i for i in range(1,10)]
def bfs(K):
    d=deque([1,2,3,4,5,6,7,8,9])
    while(len(lunlun)<K):
        s=d[0]
        d.popleft()
        n=[]
        if(s%10!=0):
            n.append((s%10-1)+s*10)
        n.append(s%10+s*10)
        if(s%10!=9):
            n.append((s%10+1)+s*10)
        lunlun.extend(n);d.extend(n)
K=int(eval(input()))
bfs(K)
print((lunlun[K-1]))
# Original solution
from collections import deque


k = int(eval(input()))

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

for _ in range(k):
    num = queue.popleft()
    a = num // 10
    b = num % 10

    if b != 0:
        queue.append(num*10 + b-1)

    queue.append(num*10 + b)
    
    if b != 9:
        queue.append(num*10 + b+1)

print(num)


# Optimized solution
from collections import deque


k = int(eval(input()))

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

for _ in range(k):
    num = queue.popleft()
    x = num % 10

    if x != 0:
        queue.append(num*10 + x-1)

    queue.append(num*10 + x)

    if x != 9:
        queue.append(num*10 + x+1)

print(num)
# Original solution
def solve(K):
    lun = [0]

    def nextLunlun(arr, d=0):
        arr[d] += 1
        if arr[d] == 10:
            if d + 1 == len(arr):
                arr.append(1)
                arr[d] = 0
                return arr
            else:
                arr = nextLunlun(arr, d + 1)
                arr[d] = arr[d + 1] - 1 if arr[d + 1] > 0 else 0
                return arr
        if d + 1 != len(arr):
            if abs(arr[d] - arr[d + 1]) > 1:
                if arr[d] < arr[d + 1]:
                    arr[d] = arr[d + 1] - 1
                    return arr
                else:
                    arr = nextLunlun(arr, d + 1)
                    arr[d] = arr[d + 1] - 1 if arr[d + 1] > 0 else 0
                    return arr
        return arr

    for _ in range(K):
        lun = nextLunlun(lun)

    ans = 0
    for i in range(len(lun)):
        ans += lun[i] * (10 ** i)

    print(ans)


if __name__ == '__main__':
    K = int(eval(input()))
    solve(K)


# Optimized solution
# 解説を参考に作成
from collections import deque


def solve(K):
    lunlun = deque([i for i in range(1, 10)])

    ans = 0
    for _ in range(K):
        ans = lunlun.popleft()
        x = ans * 10 + ans % 10
        if x % 10 != 0:
            lunlun.append(x - 1)
        lunlun.append(x)
        if x % 10 != 9:
            lunlun.append(x + 1)

    print(ans)


if __name__ == '__main__':
    K = int(eval(input()))
    solve(K)