CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque

K = int(eval(input()))
d = deque()
for i in range(1, 10):
    d.append(i)

cnt = 0
while d:
    tmp = d.popleft()
    cnt += 1
    if cnt == K:
        print(tmp)
        break
    r = tmp % 10
    if r != 0:
        d.append(tmp * 10 + r - 1)
    d.append(tmp * 10 + r)
    if r != 9:
        d.append(tmp * 10 + r + 1)

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

present = [1,2,3,4,5,6,7,8,9]
while K >= len(present):
    K -= len(present)
    next = []
    for i in range(len(present)):
        tmp = present[i]
        r = tmp % 10
        if r != 0:
            next.append(tmp * 10 + r -1)
        next.append(tmp * 10 + r)
        if r != 9:
            next.append(tmp * 10 + r +1)
    present = next

print((present[K-1]))
# Original solution
K = int(eval(input()))
import copy

present = [1,2,3,4,5,6,7,8,9]
while K >= len(present):
    K -= len(present)
    next = []
    for i in range(len(present)):
        tmp = present[i]
        r = tmp % 10
        if r != 0:
            next.append(tmp * 10 + r -1)
        next.append(tmp * 10 + r)
        if r != 9:
            next.append(tmp * 10 + r +1)
    present = next

print((present[K-1]))

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

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

while K > len(old):
    new = []
    K -= len(old)
    for i in range(len(old)):
        tmp = old[i]
        l = tmp % 10
        if l != 0:
            new.append(tmp*10+l-1)
        new.append(tmp*10+l)
        if l != 9:
            new.append(tmp*10+l+1)
    old = new[:]



print((old[K-1]))
# Original solution
def function(n):
  string = str(n)
  for i in range(len(string) - 1):
    if int(string[i]) - int(string[i + 1]) > 1:
      return i + 1
    elif int(string[i + 1]) - int(string[i]) > 1:
      return i
  return -1
 
k = int(eval(input()))
ans = []
n = 1
while len(ans) < k:
  m = function(n)
  if m == -1:
    ans.append(n)
    n += 1
  else:
    n = n + 10 ** (len(str(n)) - m - 1) - n % (10 ** (len(str(n)) - m - 1))
print((ans[-1]))

# Optimized solution
def function(n):
  string = str(n)
  for i in range(len(string) - 1):
    error = int(string[i]) - int(string[i + 1])
    if error > 1:
      return i + 1, error
    elif error < -1:
      return i, abs(error)
  return -1, 0
 
k = int(eval(input()))
ans = []
n = 1
while len(ans) < k:
  m, error = function(n)
  if m == -1:
    ans.append(n)
    n += 1
  else:
    n = n + (error - 1) * (10 ** (len(str(n)) - m - 1)) - n % (10 ** (len(str(n)) - m - 1))
print((ans[-1]))
# Original solution
def d():
    k = int(eval(input()))

    val = 0
    hits = 0
    hit_tails = {}
    while hits < k:
        val += 1
        if len(str(val)) == 1:
            hits += 1
            hit_tails[val] = int(str(val)[-1])
            # print('====', hits, val)
            pass
        else:
            lst = list(map(int, str(val)))
            # print('before:', lst)
            for i in range(len(lst) - 1):
                if lst[i] > lst[i+1] + 1:
                    lst[i+1] = lst[i] - 2
                    if(i < len(lst) - 2):
                        lst[i+2:] = [9] * len(lst[i+2:])
                    val = int(''.join(map(str, lst)))
                    # print('after1:', lst)
                    break
                elif lst[i] < lst[i+1] - 1:
                    lst[i+1:] = [9] * len(lst[i+1:])
                    val = int(''.join(map(str, lst)))
                    # print('after2:', lst)
                    break
                elif i == len(lst) - 2:
                    hits += 1
                    hit_tails[val] = int(str(val)[-1])
                    # print('====', hits, val)
                    pass

    print(val)


##########
if __name__ == "__main__":
    d()


# Optimized solution
from collections import deque


def lunlun():
    k = int(eval(input()))
    q = deque(list(range(1, 10)))

    while k > 0:
        k -= 1
        n = q.popleft()
        # print('====== popleft:', n)

        if n % 10 != 0:
            n0 = int(str(n) + str(n % 10 - 1))
            q.append(n0)
            # print('=== append:', n0)

        n1 = int(str(n) + str(n % 10))
        q.append(n1)
        # print('=== append:', n1)

        if n % 10 != 9:
            n2 = int(str(n) + str(n % 10 + 1))
            q.append(n2)
            # print('=== append:', n2)

    print(n)


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

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

  # 前後をチェックする再帰関数( 要素として深さも必要そう / DPのメモ化とか使えそう )
  # 
  # 生データ
  # 1桁
  # [1, 2, 3, 4, 5, 6, 7, 8, 9]
  # 2桁 
  # [10, 11, 12, 21, 22, 23,..., 98, 99]
  #
  # 1
  # 10 11 12
  #
  #          2
  # .. .. .. 21 22 23
  #
  # Point.
  #   1の木, 2の木と小さい順に自然となってる
  #   重複していない
  #
  # キューを使った方法の解説
  #
  # 初期状態
  # 1 2 3 4 5 6 7 8 9
  #
  # 遷移1
  # . 2 3 4 5 6 7 8 9 10 11 12
  #
  # 遷移2
  # . . 3 4 5 6 7 8 9 10 11 12 21 22 23
  #
  # 遷移3
  # . . . 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34

  # 最初の1桁データの用意
  q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

  for _ in range(k-1):
    p = q.popleft()
    l = p % 10
    # print("l:", l)

    if l - 1 >= 0:
      new_data1 = int(str(p) + str(l - 1))
      # print("new_data1:", new_data1)
      q.append(new_data1)
      # print("q:", q)
    
    new_data2 = int(str(p) + str(l))
    # print("new_data2:", new_data2)
    q.append(new_data2)
    # print("q:", q)

    if l + 1 <= 9:
      new_data3 = int(str(p) + str(l + 1))
      # print("new_data3:", new_data3)
      q.append(new_data3)
      # print("q:", q)

  # print("===============")
  print((q[0]))
  # print("===============")

if __name__ == "__main__":
  main()


# Optimized solution
from collections import deque

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

  # 前後をチェックする再帰関数( 要素として深さも必要そう / DPのメモ化とか使えそう )
  # 
  # 生データ
  # 1桁
  # [1, 2, 3, 4, 5, 6, 7, 8, 9]
  # 2桁 
  # [10, 11, 12, 21, 22, 23,..., 98, 99]
  #
  # 1
  # 10 11 12
  #
  #          2
  # .. .. .. 21 22 23
  #
  # Point.
  #   1の木, 2の木と小さい順に自然となってる
  #   重複していない
  #
  # キューを使った方法の解説
  #
  # 初期状態
  # 1 2 3 4 5 6 7 8 9
  #
  # 遷移1
  # . 2 3 4 5 6 7 8 9 10 11 12
  #
  # 遷移2
  # . . 3 4 5 6 7 8 9 10 11 12 21 22 23
  #
  # 遷移3
  # . . . 4 5 6 7 8 9 10 11 12 21 22 23 32 33 34

  # 最初の1桁データの用意
  q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

  for _ in range(k-1):
    p = q.popleft()
    l = p % 10
    # print("l:", l)

    if l - 1 >= 0:
      new_data1 = p*10 + (l - 1)
      # print("new_data1:", new_data1)
      q.append(new_data1)
      # print("q:", q)
    
    new_data2 = p*10 + l
    # print("new_data2:", new_data2)
    q.append(new_data2)
    # print("q:", q)

    if l + 1 <= 9:
      new_data3 = p*10 + (l + 1)
      # print("new_data3:", new_data3)
      q.append(new_data3)
      # print("q:", q)

  print((q[0]))

if __name__ == "__main__":
  main()
# Original solution
# D - Lunlun Number

K = int(eval(input()))
stack = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0
while len(stack) < K:
    first = int(str(stack[i])[-1:])
    if first == 0:
        stack.append(int(str(stack[i]) + str(first)))
        stack.append(int(str(stack[i]) + str(first + 1)))
    elif first == 9:
        stack.append(int(str(stack[i]) + str(first - 1)))
        stack.append(int(str(stack[i]) + str(first)))
    else:
        stack.append(int(str(stack[i]) + str(first - 1)))
        stack.append(int(str(stack[i]) + str(first)))
        stack.append(int(str(stack[i]) + str(first + 1)))        
    i += 1

print((stack[K - 1]))

# Optimized solution
# D - Lunlun Number

K = int(eval(input()))

N = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0

while len(N) < K:
    n = int(str(N[i]) + str(N[i])[-1:])
    if str(n)[-1:] == '0':
        N += [n, n + 1]
    elif str(n)[-1:] == '9':
        N += [n - 1, n]
    else:
        N += [n - 1, n, n + 1]
    i += 1

print((N[K - 1]))
# Original solution
import sys
input = sys.stdin.readline
from collections import deque

INF = float('inf')


if __name__ == '__main__':
    K = int(eval(input()))
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

    if K < 10:
        print(K)
        exit()

    counter = 0
    while True:
        counter += 1
        x = q.popleft()
        if counter != K:
            if x % 10 == 0:
                q.append(x * 10)
                q.append(x * 10 + 1)
            elif x % 10 == 9:
                q.append(x * 10 + 8)
                q.append(x * 10 + 9)
            else:
                q.append(x * 10 + (x % 10 - 1))
                q.append(x * 10 + (x % 10))
                q.append(x * 10 + (x % 10 + 1))
        else:
            print(x)
            exit()


# Optimized solution
import sys
input = sys.stdin.readline
from collections import deque

INF = float('inf')


if __name__ == '__main__':
    K = int(eval(input()))
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

    if K < 10:
        print(K)
        exit()

    counter = 0
    while True:
        counter += 1
        x = q.popleft()
        amari = x % 10
        if counter != K:
            if amari == 0:
                q.append(x * 10 + amari)
                q.append(x * 10 + (amari + 1))
            elif amari == 9:
                q.append(x * 10 + (amari - 1))
                q.append(x * 10 + amari)
            else:
                q.append(x * 10 + (amari - 1))
                q.append(x * 10 + amari)
                q.append(x * 10 + (amari + 1))
        else:
            print(x)
            exit()
# Original solution
import sys
input = sys.stdin.readline
from collections import deque

INF = float('inf')


if __name__ == '__main__':
    K = int(eval(input()))
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

    if K < 10:
        print(K)
        exit()

    counter = 0
    while True:
        counter += 1
        x = q.popleft()
        amari = x % 10
        if counter != K:
            if amari == 0:
                q.append(x * 10 + amari)
                q.append(x * 10 + (amari + 1))
            elif amari == 9:
                q.append(x * 10 + (amari - 1))
                q.append(x * 10 + amari)
            else:
                q.append(x * 10 + (amari - 1))
                q.append(x * 10 + amari)
                q.append(x * 10 + (amari + 1))
        else:
            print(x)
            exit()


# Optimized solution
import sys
input = sys.stdin.readline
from collections import deque

INF = float('inf')


if __name__ == '__main__':
    K = int(eval(input()))
    q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

    if K < 10:
        print(K)
        exit()

    counter = 0
    while True:
        counter += 1
        x = q.popleft()
        amari = x % 10
        if counter != K:
            if amari > 0:
                q.append(x * 10 + (amari - 1))
            q.append(x * 10 + amari)
            if amari < 9:
                q.append(x * 10 + (amari + 1))
        else:
            print(x)
            exit()
# Original solution
k = int(eval(input()))
n = 0

def ff(s, i):
    for j in range(i+1, len(s)):
        #print(s[j-1])
        if s[j-1] > 0:
            s[j] = s[j-1] - 1
        else:
            s[j] = 0
    return s

def next(s):
    ls = len(s)
    for i in range(ls-1, 0, -1):
        if s[i-1] >= s[i] and s[i] != 9:
            s[i] += 1
            #print(s[i-1],s[i])
            return ff(s, i)
    if s[0] == 9:
        return [1] + ([0] * ls)
    else:
        s[0] += 1
        return ff(s, 0)

if k < 10:
    print(k)
    exit()

ans = [1,0]
for i in range(k - 10):
    ans = next(ans)
#print(ans)
print((''.join(map(str, ans))))






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

from collections import deque
que = deque(r)

if k < 10:
    print(k)
    exit()
while len(r) <= k:
    ri = que.popleft()
    for j in range(max(0, ri[-1]-1), min(9, ri[-1]+1)+1):
        rj = ri.copy()
        rj.append(j)
        r.append(rj)
        que.append(rj)
        #print(que)
#print(r[k-1])
print((''.join(map(str, r[k-1]))))
# Original solution
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

K = int(eval(input()))

lunlun = []
def dfs(i,before):
    if i == 11:
        return
    lunlun.append(before)
    back = before%10
    for j in range(-1,2):
        t = back + j
        if 0 <= t < 10:
            dfs(i + 1,before*10 + t)

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


# Optimized solution
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

Lunlun = []
K = int(eval(input()))

def dfs(i,before):
    if i == 10:
        return
    Lunlun.append(before)
    x = before%10
    for d in (-1,0,1):
        y = x + d
        if y < 0 or y >= 10:
            continue
        dfs(i + 1,before*10 + y)

for i in range(1,10):
    dfs(0,i)
Lunlun.sort()
ans = Lunlun[K - 1]
print(ans)
# Original solution
def main():
    from functools import lru_cache
    import sys

    sys.setrecursionlimit(10 ** 7)

    @lru_cache(maxsize=None)
    def make_number(digit, p=0):
        if digit == 0:
            memo.append(p)
            if len(memo) == k + 1:
                print(p)
                exit()
            return

        if p == 0:
            # 前の位がない
            for x in range(1, 10):
                make_number(digit - 1, x)

        else:
            r = p % 10
            # 前の位がある
            for x in range(max(0, r - 1), min(9, r + 1) + 1):
                make_number(digit - 1, p * 10 + x)

    k = int(eval(input()))

    memo = []

    for digit in range(11):
        make_number(digit)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


# Optimized solution
from collections import deque

K = int(eval(input()))

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

idx = 1
while idx < K:
    x = dq.popleft()
    idx += 1

    r = x % 10

    if r > 0:
        nx = (x * 10) + (r - 1)
        dq.append(nx)

    nx = (x * 10) + (r)
    dq.append(nx)

    if r < 9:
        nx = (x * 10) + (r + 1)
        dq.append(nx)

ans = dq.popleft()
print(ans)
# Original solution
from collections import deque

K = int(eval(input()))

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

idx = 1
while idx < K:
    x = dq.popleft()
    idx += 1

    r = x % 10

    if r > 0:
        nx = (x * 10) + (r - 1)
        dq.append(nx)

    nx = (x * 10) + (r)
    dq.append(nx)

    if r < 9:
        nx = (x * 10) + (r + 1)
        dq.append(nx)

ans = dq.popleft()
print(ans)


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

    K = int(eval(input()))

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

    idx = 0
    while dq:
        x = dq.popleft()
        idx += 1
        if idx == K:
            print(x)
            return

        r = x % 10
        if r > 0:
            dq.append(x * 10 + r - 1)
        dq.append(x * 10 + r)
        if r < 9:
            dq.append(x * 10 + r + 1)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())
# Original solution
def make_tree(G,keta,count):
    if keta==1:
        num =[]
        for i in range(1,10):
            count+=1
            if count ==k:
                print(i)
                exit()
            else:
                num.append(i)
        G.append(num)
        make_tree(G,2,count)
    else:
        
        num_list = G[keta-2]
        num_lis =[]
        for num in num_list:
            num_str = str(num)
            num_e = int(num_str[-1])
            if num_e == 0:
                count +=1
                if count == k :
                    print((int(num_str + "0")))
                    exit()
                num_lis.append(int((num_str)+"0"))
                count+=1
                if count == k :
                    print((int(num_str + "1")))
                    exit()
                num_lis.append(int((num_str)+"1"))
            elif num_e == 9:
                count +=1
                if count == k :
                    print((int(num_str + "8")))
                    exit()
                num_lis.append(int((num_str)+"8"))
                count+=1
                if count == k :
                    print((int(num_str + "9")))
                    exit()
                num_lis.append(int((num_str)+"9"))
            else:
                count +=1
                if count == k :
                    print((int(num_str + str(num_e-1))))
                    exit()
                num_lis.append(int(num_str + str(num_e-1)))
                count+=1
                if count == k :
                    print((int(num_str + str(num_e))))
                    exit()
                num_lis.append(int(num_str + str(num_e)))
                count+=1
                if count == k :
                    print((int(num_str + str(num_e+1))))
                    exit()
                num_lis.append(int(num_str + str(num_e+1)))
        G.append(num_lis)

        make_tree(G,keta+1,count)


k = int(eval(input()))
G=[]
make_tree(G,1,0)


# Optimized solution
def is_count_k(count,n):
    count +=1
    if count == k :
        print(n)
        exit()
    
    return count
def make_tree(G,keta,count):
    num_list = G[keta-2]
    new_list =[]
    for num in num_list:
        r = num%10
        if r != 0 :
            count = is_count_k(count,num*10 + (r-1))
            new_list.append(num*10 + r-1)
        count = is_count_k(count,num*10+r)
        new_list.append(num*10 + r)
        if r != 9:
            count = is_count_k(count,num*10+(r +1))
            new_list.append(num*10+(r +1))
    G.append(new_list)
    make_tree(G,keta+1,count)
k = int(eval(input()))
G=[]
if k < 10:
    print(k)
    exit()
G.append([1,2,3,4,5,6,7,8,9])
make_tree(G,2,9)
# Original solution
import sys
sys.setrecursionlimit(3000)
k = int(eval(input()))

ans = []

def solve(x, l):
    if int(x) > 3234566667:
        return l

    l.append(int(x))
    if x[-1] == '0':
        solve(x + '0', l)
        solve(x + '1', l)
    elif x[-1] == '9':
        solve(x + '9', l)
        solve(x + '8', l)
    else:
        last_digit = int(x[-1])
        for i in range(-1, 2):
            new_digit = last_digit + i
            solve(x + str(new_digit), l)

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

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


#初めに、1~9まではキューに入れておく
q = deque([i for i in range(1, 10)])
ans = 0
while True:
    v = q.popleft()
    ans += 1
    if ans == k:
        print(v)
        break
    
    #末尾の1桁を求める
    last_digit = v % 10
    #求めた末尾の1桁との差が1になる数字を最後の1桁にする
    #つまり、末尾の1桁に対して-1,+0,+1とする計算を行う
    for i in range(-1, 2):
        new_digit = last_digit + i
        if new_digit < 0 or new_digit > 9:
            continue
        q.append(v * 10 + new_digit)
# Original solution
def add():
    for i in ans[cnt-1]:
        i=str(i)
        last=i[-1]
        last=int(last)
        for j in range(last-1,last+2):
            if j==10 or j==-1:
                continue
            tmp=i
            tmp+=str(j)
            ans[cnt].append(int(tmp))

n=int(eval(input()))
ans=[[]for i in range(10)]
cnt=1
for i in range(1,10):
    ans[0].append(i)

for i in range(9):
    add()
    cnt+=1
merged=[]
for i in ans:
    merged+=i
merged=sorted(merged)
print((merged[n-1]))

# Optimized solution
def dfs(x):
    ans.append(x)
    if len(str(x))==10:
        return
    
    last=x%10
    
    for i in [last-1,last,last+1]:
        if 0<=i<=9:
            dfs(10*x+i)

k=int(eval(input()))
ans=[]
for i in range(1,10):
    dfs(i)
    
ans=sorted(ans)
print((ans[k-1]))
# Original solution
k = int(eval(input()))
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
while len(ans) < k:
    b = []
    for i in a:
        if i == "323456667":
            break
        intil = int(i[-1])
        c = [i + j for j in illist[intil]]
        b = b + c
    a = b
    ans = ans + b

print((ans[k-1]))

# Optimized solution
k = int(eval(input()))
from collections import deque
q = deque()
a = list(map(str, list(range(1, 10))))
ans = a + []
illist = []
for i in range(10):
    if i == 0:
        illist.append(["0","1"])
    elif i == 9:
        illist.append(["8","9"])
    else:
        illist.append([str(i-1),str(i),str(i+1)])
for i in range(1,10):
    q.append(str(i))

node = "0"
while node != "323456667":
    node = q.popleft()
    for j in illist[int(node[-1])]:
        nodej = node+j
        q.append(nodej)
        a.append(nodej)

print((a[k - 1]))
# Original solution
K=int(eval(input()))
N=0 #現在のルンルン数の数
lun=list(range(1,10))
while 1:
    N+=1
    x=lun[N-1]
    if x%10 != 0:
        lun.append(10*x+x%10-1)
    lun.append(10*x+x%10)
    if x%10 != 9:
        lun.append(10*x+x%10+1)
    if N==K:
        break
print((lun[N-1]))


# Optimized solution
K=int(eval(input()))
# K=15
lun=list(range(1,10))
i=0
while 1:
    ichi=lun[i]%10
    if ichi!=0:
        lun.append(lun[i]*10+ichi-1)
    lun.append(lun[i]*10+ichi)
    if ichi!=9:
        lun.append(lun[i]*10+ichi+1)
    i+=1
    if i==K:
        break
print((lun[i-1]))
# Original solution
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

MAX = 3234566667
ans = []
def rec(x):
    if int(x) > MAX:
        return
    ans.append(int(x))
    last = int(x[-1])
    rec(x+str(last))
    if last != 0:
        rec(x+str(last-1))
    if last != 9:
        rec(x+str(last+1))
    return

K = INT()

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

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


# Optimized solution
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

def check(x):
    x = str(x)
    N = len(x)
    dp0 = list2d(N+1, 10, 0)
    dp1 = list2d(N+1, 10, 0)
    a = int(x[0])
    dp0[1][a] = 1
    for j in range(1, a):
        dp1[1][j] = 1
    for i in range(2, N+1):
        for j in range(1, 10):
            dp1[i][j] = 1
    for i, a in enumerate(x):
        a = int(a)
        for j in range(10):
            for k in range(10):
                if abs(j - k) >= 2:
                    continue
                if k > a:
                    dp1[i+1][k] += dp1[i][j]
                elif k == a:
                    dp0[i+1][k] += dp0[i][j]
                    dp1[i+1][k] += dp1[i][j]
                else:
                    dp1[i+1][k] += dp0[i][j]
                    dp1[i+1][k] += dp1[i][j]
    ans = sum(dp0[N]) + sum(dp1[N])
    return ans >= K

K = INT()

res = bisearch_min(0, 10**10, check)
print(res)