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]))
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]))
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]))

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]))

-li = [i for i in range(1, 10)] +lunlun = [i for i in range(1, 10)] -    d = deque() -    for i in range(1, 10): -        d.append(str(i)) -    while len(li) < K: +    d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) +    while len(lunlun) < K: -        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])) +        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) -print((li[K - 1])) +print((lunlun[K - 1]))