CodeEff/ECCO huggingface dataset:
# Original solution
#n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)

def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(eval(input()))
t = True
k=1
b = 0
while t:
    a = runrun(k)
    b = 0
    #k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b+=(len(a[i]))
        #k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0
#まずk-1桁までのるんるん数の数を数える
            for i in range(len(tmp)):
                c += (len(tmp[i]))
            s = a[k-1][x-c-1]
            print((int(s)))
    else:
        k += 1

# Optimized solution
#n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)

from functools import lru_cache
@lru_cache(maxsize=None)

def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(eval(input()))
t = True
k=1
b = 0
while t:
    a = runrun(k)
    b = 0
    #k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b+=(len(a[i]))
        #k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0
#まずk-1桁までのるんるん数の数を数える
            for i in range(len(tmp)):
                c += (len(tmp[i]))
            s = a[k-1][x-c-1]
            print((int(s)))
    else:
        k += 1
# Original solution
import collections

k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
for _ in range(k):
    x = Q.popleft()
    if x%10:
        Q.append(10*x + x%10 - 1)
    Q.append(10*x + x%10)
    if x%10 != 9:
        Q.append(10*x + x%10 + 1)
print(x)


# Optimized solution
import collections

k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
chk = False
for i in range(k):
    x = Q.popleft()
    if i + len(Q) > k:
        chk = True
    if chk:
        continue
    else:
        if x%10:
            Q.append(10*x + x%10 - 1)
        Q.append(10*x + x%10)
        if x%10 != 9:
            Q.append(10*x + x%10 + 1)
print(x)
# Original solution
import collections

k = int(eval(input()))
Q = collections.deque([int(i) for i in range(1, 10)])
chk = False
for i in range(k):
    x = Q.popleft()
    if i + len(Q) > k:
        chk = True
    if chk:
        continue
    else:
        if x%10:
            Q.append(10*x + x%10 - 1)
        Q.append(10*x + x%10)
        if x%10 != 9:
            Q.append(10*x + x%10 + 1)
print(x)


# Optimized solution
import collections

def main():
    k = int(eval(input()))
    Q = collections.deque([int(i) for i in range(1, 10)])
    chk = False
    for i in range(k):
        x = Q.popleft()
        if i + len(Q) > k:
            chk = True
        if chk:
            continue
        else:
            if x%10:
                Q.append(10*x + x%10 - 1)
            Q.append(10*x + x%10)
            if x%10 != 9:
                Q.append(10*x + x%10 + 1)
    print(x)

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K = ir()
A = deque([x for x in range(1, 10)])
count = 0
while True:
    cur = A.popleft()
    count += 1
    if count == K:
        answer = cur
        break
    next = 10 * cur + (cur % 10)
    if cur % 10 != 0:
        A.append(next-1)
    A.append(next)
    if cur % 10 != 9:
        A.append(next+1)

print(answer)


# Optimized solution
# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K = ir()
num = -1

def dfs(A, i, bl):
    global num
    if i == 11:
        num += 1
        if num == K:
            ans = ''.join(map(str, A))
            ans = int(ans)
            print(ans)
            exit()
        return
    last = A[-1]
    if bl:
        dfs([0], i+1, True)
        for j in range(1, 10):
            dfs([j], i+1, False)
    else:
        if last > 0:
            dfs(A+[last-1], i+1, False)
        dfs(A+[last], i+1, False)
        if last < 9:
            dfs(A+[last+1], i+1, False)

dfs([0], 0, True)
# Original solution
K = int(eval(input()))

k = K - 1

numbers = {
    0: 1
}

while k > 0:
    k -= 1
    for i in range(len(numbers)):
        n = numbers[i]
        if n == 9:
            continue

        if abs(numbers.get(i - 1, n) - (n + 1)) <= 1 and abs(numbers.get(i + 1, n) - (n + 1)) <= 1:
            numbers[i] += 1
            j = i - 1
            while j >= 0:
                numbers[j] = max(numbers[j + 1] - 1, 0)
                j -= 1
            break
    else:
        for key in list(numbers.keys()):
            numbers[key] = 0
        numbers[len(numbers)] = 1

print((''.join([str(numbers[i]) for i in range(len(numbers))])[::-1]))


# Optimized solution
from collections import deque

K = int(eval(input()))

queue = deque(list(range(1, 10)))

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

print(x)
# Original solution
import sys
from collections import deque

def solve():
      input = sys.stdin.readline
      K = int(eval(input()))
      low, high = 0, 3234566668
      while high - low > 1:
            mid = (low + high) // 2
            midS = str(mid)
            lenS = len(midS)
            q = deque()
            for j in range(lenS):
                  for i in range(1, 10): q.append((i, i, j + 1))
            count = 0
            isRunrun = False
            while q:
                  ns, last, length = q.pop()
                  if length == lenS:
                        if ns <= mid: count += 1
                        if ns == mid: isRunrun = True
                  else:
                        if last == 0: 
                              q.append((ns*10 + 1, 1, length + 1))
                              q.append((ns*10 + 0, 0, length + 1))
                        elif last == 9: 
                              q.append((ns*10 + 8, 8, length + 1))
                              q.append((ns*10 + 9, 9, length + 1))
                        else:
                              q.append((ns*10 + last+1, last + 1, length + 1))
                              q.append((ns*10 + last-1, last - 1, length + 1))
                              q.append((ns*10 + last, last, length + 1))
            if count > K: high = mid
            elif count == K:
                  if isRunrun: low = mid
                  else: high = mid
            else: low = mid
            #print(mid, count)
      print(low)
            
      return 0

if __name__ == "__main__":
      solve()

# Optimized solution
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    K = int(eval(input()))
    q = deque()
    for i in range(9): q.append((i + 1, i + 1))
    lunlun = 1
    while lunlun < K:
        nowNum, lastNum = q.popleft()
        if lastNum > 0: q.append((nowNum * 10 + lastNum - 1, lastNum - 1))
        q.append((nowNum * 10 + lastNum, lastNum))
        if lastNum < 9: q.append((nowNum * 10 + lastNum + 1, lastNum + 1))
        lunlun += 1
    ans, lastNum = q.popleft()
    print(ans)

    return 0

if __name__ == "__main__":
    solve()
# Original solution
K = int(eval(input()))
a = set([1,2,3,4,5,6,7,8,9])
prev = set([1,2,3,4,5,6,7,8,9])

while len(a) < K:
    temp = set()
    for now in prev:
        c = now%10
        if c == 0:
            temp.add(now*10)
            temp.add(now*10+1)
        elif c == 9:
            temp.add(now*10+9)
            temp.add(now*10+8)
        else:
            temp.add(now*10+c-1)
            temp.add(now*10+c)
            temp.add(now*10+c+1)
    prev = temp
    a = a|temp
print((sorted(list(a))[K-1]))


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

while len(S) < K:
    temp = set([])
    for e in prev:
        if e%10 == 0:
            temp.add(e*10)
            temp.add(e*10+1)
        elif e%10 == 9:
            temp.add(e*10+8)
            temp.add(e*10+9)
        else:
            temp.add(e*10+e%10-1)
            temp.add(e*10+e%10)
            temp.add(e*10+e%10+1)
    prev = temp
    S = S|temp
print((sorted(list(S))[K-1]))
# Original solution
k = int(eval(input()))

def dfs(d, val, A):
	A.append(val)

	if d == 10:
		return

	for i in range(-1, 2):
		add = (val % 10) + i
		if add >= 0 and add <= 9:
			dfs(d + 1, val * 10 + add, A)

A = []
for v in range(1, 10): # 呼び出し
	dfs(1, v, A)
A.sort()
print((A[k - 1]))

# Optimized solution

def calc_next(arr):
	res = []
	for val in arr:
		for j in range(-1, 2):
			add = (val % 10) + j
			if add >= 0 and add <= 9:
				res.append(val * 10 + add)
	return res

k = int(eval(input()))
cur = []
A = []

for v in range(1, 10):
	cur.append(v)
	A.append(v)

for d in range(1, 10):
	cur = calc_next(cur)
	for val in cur:
		A.append(val)

print((A[k - 1]))
# Original solution
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    K = int(readline())

    queue = deque([])
    for i in range(1,10):
        queue.append(i)
    
    for i in range(K):
        x = queue.popleft()
        r = x % 10
        if r != 0:
            queue.append(10*x + r - 1)
        queue.append(10*x + r)
        if x % 10 != 9:
            queue.append(10*x + r + 1)
    
    print(x)


if __name__ == "__main__":
    main()


# Optimized solution
# 桁dp + 二分探索
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def lunlun_num(N):
    N = str(N)
    L = len(N)

    dp = [[0]*10 for j in range(L)]
    for j in range(1,int(N[0])):
        dp[0][j] = 1

    flag = True
    for i in range(L-1):
        d = int(N[i+1])
        b = int(N[i])
        
        dp[i+1][0] += dp[i][0] + dp[i][1]
        dp[i+1][9] += dp[i][8] + dp[i][9]
        for j in range(1,9):
            dp[i+1][j] += dp[i][j-1] + dp[i][j] + dp[i][j+1]
        for j in range(1,10):
            dp[i+1][j] += 1

        if flag:
            if d < b - 1:
                flag = False
            elif d <= b + 1:
                for j in range(max(0, b-1),d):
                    dp[i+1][j] += 1
            else:
                for j in range(max(0, b-1),b+2):
                    dp[i+1][j] += 1
                    flag = False

    return sum(dp[L-1]) + 1 if flag else sum(dp[L-1])


def main():
    K = int(readline())

    # xを決め打って二分探索
    left = 0
    right = 10**10
    while left + 1 < right:
        x = (left + right) // 2

        if lunlun_num(x) >= K:
            right = x
        else:
            left = x
    
    print(right)


if __name__ == "__main__":
    main()
# Original solution
def solve():
    K = int(eval(input()))
    cnt = 0
    n_digit = 1
    numbers = []
    while cnt < K:
        numbers = []
        dfs("", numbers, n_digit)
        cnt += len(numbers)
        n_digit += 1
    
    print((numbers[-(cnt - K + 1)]))
    
def dfs(now, numbers, n_digit):
    if len(now) == n_digit:
        numbers.append(now)
        return
    
    if now == "":
        for i in range(1,10):
            dfs(now+str(i), numbers, n_digit)
    else:
        last_num = int(now[-1])
        if last_num - 1 >= 0:
            dfs(now+str(last_num-1), numbers, n_digit)

        dfs(now+str(last_num), numbers, n_digit)

        if last_num + 1 <= 9:
            dfs(now+str(last_num+1), numbers, n_digit)

if __name__ == '__main__':
    solve()

# Optimized solution
from collections import deque
def solve():
    K = int(eval(input()))
    q = deque(list(range(1,10)))
    cnt = 0

    tmp = 0
    while cnt < K:
        tmp = q.popleft()
        cnt += 1

        ones_place = tmp % 10
        if ones_place != 0:
            q.append(tmp*10+ones_place-1)
        q.append(tmp*10+ones_place)
        if ones_place != 9:
            q.append(tmp*10+ones_place+1)
    
    print(tmp)
        
if __name__ == '__main__':
    solve()
# Original solution
def solve():
    K = int(eval(input()))
    all = []
    for i in range(1,10):
        dfs(1,i,all)
    
    all.sort()
    print((all[K-1]))
    
def dfs(d, val, all):
    all.append(val)

    if d == 10:
        return
    
    for j in [-1,0,1]:
        add = val % 10 + j
        if 0 <= add <= 9:
            dfs(d+1, val*10+add, all)

if __name__ == '__main__':
    solve()

# Optimized solution
def solve():
    K = int(eval(input()))
    lunluns = []
    for i in range(1,10):
        dfs(1,i,lunluns)
    
    lunluns.sort()
    print((lunluns[K-1]))

def dfs(d,now,lunluns):
    lunluns.append(now)

    if d == 10:
        return
    
    for i in [-1,0,1]:
        add = now % 10 + i

        if 0 <= add <= 9:
            dfs(d+1,now*10+add, lunluns)
        
if __name__ == '__main__':
    solve()
# Original solution
import sys
sys.setrecursionlimit(20000000)
k = int(eval(input()))

def dfs(l, lim):
    if lim == 10:
        return l
    new_l = []
    for num in l:
        last = num % 10
        base = num * 10
        if 1 <= last <= 8:
            for i in [last-1, last, last+1]:
                if base + i <= 3234566667:
                    new_l.append(base + i)
        elif last == 0:
            for i in [0, 1]:
                if base + i <= 3234566667:
                    new_l.append(base + i)
        else:
            for i in [8, 9]:
                if base + i <= 3234566667:
                    new_l.append(base + i)
    return l + new_l + dfs(new_l, lim+1)

ans = list(set(dfs([1, 2, 3, 4, 5, 6, 7, 8, 9], 0)))
ans.sort()

print((ans[k-1]))


# Optimized solution
from collections import deque

k = int(eval(input()))
que = deque([i for i in range(1, 10)])
i = 0
while True:
    i += 1
    num = que.popleft()
    if i == k:
        print(num)
        exit()
    if num % 10 > 0:
        que.append(num * 10 + ((num % 10) - 1))
    que.append(num * 10 + (num % 10))
    if num % 10 < 9:
        que.append(num * 10 + ((num % 10) + 1))
# Original solution
# -*- coding: utf-8 -*-
from collections import deque
k = int(eval(input()))

dq = deque(list(range(1, 10)))
rep = 0
while rep < k:
    now = dq.popleft()
    rep+=1
    for i in (-1, 0, 1):
        if 0<=now%10+i<10:
            dq.append(now*10+now%10+i)
print(now)


# Optimized solution
def main():
    k = int(eval(input()))
    a = [i for i in range(1,10)]
    x = 0
    while(1):
        if k <= len(a):
            print((a[k-1]))
            return
        for i in range(-1,2):
            d = a[x]%10 +i
            if 0 <= d and d < 10:
                a.append(a[x]*10 + d)
        x+=1

if __name__ == "__main__":
    main()
# Original solution
n = int(eval(input()))
l = [_ for _ in range(1,10)]

for i in range(10**5):
    if str(l[i])[-1] == '0':
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)

    elif str(l[i])[-1] == '9':
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))

    else:
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)

print((l[n-1]))

# Optimized solution
n = int(eval(input()))
l = [_ for _ in range(1,10)]

cnt = 9
for i in range(10**5):
    if cnt >= n:
        break
    if str(l[i])[-1] == '0':
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)
        cnt += 2

    elif str(l[i])[-1] == '9':
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))
        cnt += 2

    else:
        l.append(l[i]*10 + int(str(l[i])[-1]) - 1)
        l.append(l[i]*10 + int(str(l[i])[-1]))
        l.append(l[i]*10 + int(str(l[i])[-1]) + 1)
        cnt += 3

print((l[n-1]))
# Original solution
from collections import deque

q = deque([1,2,3,4,5,6,7,8,9])
cnt = 0
l = []
used = set()

while cnt<100000:
    p = q.popleft()
    if p in used:continue
    used.add(p)
    l.append(p)
    cnt += 1
    for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
        q.append(10*p+i)

N = int(eval(input()))
print((l[N-1]))

# Optimized solution
from collections import deque


def solve():
    N = int(eval(input()))
    q = deque([1,2,3,4,5,6,7,8,9])
    cnt = 0
    l = []
    used = set()

    while cnt<N:
        p = q.popleft()
        if p in used:continue
        used.add(p)
        l.append(p)
        cnt += 1
        for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
            q.append(10*p+i)

    print((l[N-1]))


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


def solve():
    N = int(eval(input()))
    q = deque([1,2,3,4,5,6,7,8,9])
    cnt = 0
    l = []
    used = set()

    while cnt<N:
        p = q.popleft()
        if p in used:continue
        used.add(p)
        l.append(p)
        cnt += 1
        for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
            q.append(10*p+i)

    print((l[N-1]))


if __name__ == "__main__":
    solve()


# Optimized solution
from collections import deque


def solve():
    N = int(eval(input()))
    q = deque([1,2,3,4,5,6,7,8,9])
    cnt = 0
    l = []

    while cnt<N:
        p = q.popleft()
        l.append(p)
        cnt += 1
        for i in range(max((p%10)-1,0), min((p%10)+1, 9)+1):
            q.append(10*p+i)

    print((l[N-1]))


if __name__ == "__main__":
    solve()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
q = [(i + 1) for i in range(9)]
if k < 10:
    print(k)
    exit()
cnt = 9
while q:
    x = q.pop(0)
    y = int(str(x)[-1])
    if y != 0:
        cnt += 1
        if cnt == k:
            print((10 * x + y - 1))
            exit()
        q.append(10 * x + y - 1)
    cnt += 1
    if cnt == k:
        print((10 * x + y))
        exit()
    q.append(10 * x + y)
    if y != 9:
        cnt += 1
        if cnt == k:
            print((10 * x + y + 1))
            exit()
        q.append(10 * x + y + 1)


# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

k = int(readline())
q = deque(list(map(str, list(range(1, 10)))))
for i in range(k - 1):
    x = q.popleft()
    y = int(x[-1])
    if y != 0:
        q.append(x + str(y - 1))
    q.append(x + x[-1])
    if y != 9:
        q.append(x + str(y + 1))
print((q[0]))
# Original solution
import sys
from collections import deque
sys.setrecursionlimit(10**7)
k = int(eval(input()))
ans = []
def bfs(que):
    finished = set()
    while que and len(ans) <= 10**6:
        x = que.popleft()
        ans.append(int(x))
        if x not in finished:
            finished.add(x)
            p = int(x[-1])
            que.append(x + str(p))
            if 1 <= p <= 8:
                que.append(x + str(p+1))
                que.append(x + str(p-1))
            elif p == 0:
                que.append(x + str(p+1))
            else:
                que.append(x + str(p-1))
que = deque([])
for i in range(1,10):
    que.append(str(i))
bfs(que)
ans.sort()
print((ans[k-1]))

# Optimized solution
import sys
from collections import deque
sys.setrecursionlimit(10**7)
k = int(eval(input()))
ans = []
def bfs(que):
    finished = set()
    while que and len(ans) <= 10**5:
        x = que.popleft()
        ans.append(int(x))
        if x not in finished:
            finished.add(x)
            p = int(x[-1])
            if 1 <= p <= 8:
                que.append(x + str(p-1))
                que.append(x + str(p))
                que.append(x + str(p+1))
            elif p == 0:
                que.append(x + str(p))
                que.append(x + str(p+1))
            else:
                que.append(x + str(p-1))
                que.append(x + str(p))
que = deque([])
for i in range(1,10):
    que.append(str(i))
bfs(que)
ans.sort()
print((ans[k-1]))
# Original solution
K = int(eval(input()))
L = [i for i in range(1, 10)]
cnt = 9
i = 0

while K > cnt:
  x = L[i]
  r = x % 10
  if r != 0:
    L.append(10*x + r - 1)
    cnt += 1
  L.append(10*x + r)
  cnt += 1
  if r != 9:
    L.append(10*x + r + 1)
    cnt += 1
  i += 1

print((L[K-1]))

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

C = [[0]*10 for _ in range(10)]
C[0] = [1]*10
D = {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]}

for i in range(1, 10):
  for j in range(10):
    if j == 0:
      C[i][j] = C[i-1][j] + C[i-1][j+1]
    elif j == 9:
      C[i][j] = C[i-1][j-1] + C[i-1][j]
    else:
      C[i][j] = C[i-1][j-1] + C[i-1][j] + C[i-1][j+1]

ans = []
temp = K
Flag = True

for i in range(10):
  if Flag:
    for j in range(1, 10):
      temp -= C[i][j]
      if temp <= 0:
        temp += C[i][j]
        r = i
        ans.append(j)
        Flag = False
        break
  else:
    break

def f(x, r):
  temp = x
  r -= 1
  for j in D[ans[-1]]:
    temp -= C[r][j]
    if temp <= 0:
      temp += C[r][j]
      ans.append(j)
      break
  return temp, r

while r >= 1:
  temp, r = f(temp, r)

print(("".join([str(i) for i in ans])))
# Original solution
N=int(eval(input()))

list = []

def standard(n, cur):
  if n == 0:
    ##print(''.join(cur))
    add = ''.join(cur)
    if str(add).isnumeric() and add != "0":
        list.append(int(add))
  else:
    newC = chr(ord(cur[-1]) + 1)
    standard(n - 1, cur + [newC])
    newC2 = chr(ord(cur[-1]) - 1)
    standard(n - 1, cur + [newC2])
    newC3 = chr(ord(cur[-1]))
    standard(n - 1, cur + [newC3])

for i in range(10):
    for j in range(9):
        standard(i, [str(j+1)])

list = sorted(list)
print((list[N-1]))

# Optimized solution
N=int(eval(input()))
list = []

def standard(n, cur):
  if n == 0:
    add = ''.join(cur)
    if str(add).isnumeric():
        list.append(int(add))
  else:
    newC = chr(ord(cur[-1]) - 1)
    standard(n - 1, cur + [newC])
    newC2 = chr(ord(cur[-1]))
    standard(n - 1, cur + [newC2])
    newC3 = chr(ord(cur[-1]) + 1)
    standard(n - 1, cur + [newC3])

for i in range(10):
    for j in range(9):
        standard(i, [str(j+1)])

print((list[N-1]))