from sys import stdin,setrecursionlimit

k = int(stdin.readline().rstrip())

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

#ルンルン最初の数

def runrun(before,kazu):

    if before == 0:

        li.append(int(kazu+str(before+1)))

        li.append(int(kazu+str(before)))

    elif before == 9:

        li.append(int(kazu+str(before-1)))

        li.append(int(kazu+str(before)))

    else:

        li.append(int(kazu+str(before+1)))

        li.append(int(kazu+str(before-1)))

        li.append(int(kazu+str(before)))

    if len(kazu)+1 >= 10:

        return

    else:

        if before == 0:

            return runrun(before+1,kazu+str(before+1)),runrun(before,kazu+str(before))

        elif before == 9:

            return runrun(before-1,kazu+str(before-1)),runrun(before,kazu+str(before))

        else:

            return runrun(before+1,kazu+str(before+1)),runrun(before-1,kazu+str(before-1)),runrun(before,kazu+str(before))

for i in range(1,10):

    runrun(i,str(i))

li.sort()

print((li[k-1]))
from queue import deque



k = int(eval(input()))

que = deque()

for i in range(1,10):

    que.append(i)



for i in range(k):

    if i == (k-1):

        print((que.popleft()))

        exit()

    now = que.popleft()

    if now%10 != 0:

        que.append(now*10+now%10-1)

    que.append(now*10+now%10)

    if now%10 != 9:

        que.append(now*10+now%10+1)
from sys import stdin, setrecursionlimit

k = int(stdin.readline().rstrip())
li = [i for i in range(1, 10)]
# ルンルン最初の数
def runrun(before, kazu):
    if before == 0:
        li.append(int(kazu + str(before + 1)))
        li.append(int(kazu + str(before)))
    elif before == 9:
        li.append(int(kazu + str(before - 1)))
        li.append(int(kazu + str(before)))
    else:
        li.append(int(kazu + str(before + 1)))
        li.append(int(kazu + str(before - 1)))
        li.append(int(kazu + str(before)))
    if len(kazu) + 1 >= 10:
        return
    else:
        if before == 0:
            return runrun(before + 1, kazu + str(before + 1)), runrun(
                before, kazu + str(before)
            )
        elif before == 9:
            return runrun(before - 1, kazu + str(before - 1)), runrun(
                before, kazu + str(before)
            )
        else:
            return (
                runrun(before + 1, kazu + str(before + 1)),
                runrun(before - 1, kazu + str(before - 1)),
                runrun(before, kazu + str(before)),
            )


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

from queue import deque

k = int(eval(input()))
que = deque()
for i in range(1, 10):
    que.append(i)
for i in range(k):
    if i == (k - 1):
        print((que.popleft()))
        exit()
    now = que.popleft()
    if now % 10 != 0:
        que.append(now * 10 + now % 10 - 1)
    que.append(now * 10 + now % 10)
    if now % 10 != 9:
        que.append(now * 10 + now % 10 + 1)

-from sys import stdin, setrecursionlimit +from queue import deque -k = int(stdin.readline().rstrip()) -li = [i for i in range(1, 10)] -# ルンルン最初の数 -def runrun(before, kazu): -    if before == 0: -        li.append(int(kazu + str(before + 1))) -        li.append(int(kazu + str(before))) -    elif before == 9: -        li.append(int(kazu + str(before - 1))) -        li.append(int(kazu + str(before))) -    else: -        li.append(int(kazu + str(before + 1))) -        li.append(int(kazu + str(before - 1))) -        li.append(int(kazu + str(before))) -    if len(kazu) + 1 >= 10: -        return -    else: -        if before == 0: -            return runrun(before + 1, kazu + str(before + 1)), runrun( -                before, kazu + str(before) -            ) -        elif before == 9: -            return runrun(before - 1, kazu + str(before - 1)), runrun( -                before, kazu + str(before) -            ) -        else: -            return ( -                runrun(before + 1, kazu + str(before + 1)), -                runrun(before - 1, kazu + str(before - 1)), -                runrun(before, kazu + str(before)), -            ) - - +k = int(eval(input())) +que = deque() -    runrun(i, str(i)) -li.sort() -print((li[k - 1])) +    que.append(i) +for i in range(k): +    if i == (k - 1): +        print((que.popleft())) +        exit() +    now = que.popleft() +    if now % 10 != 0: +        que.append(now * 10 + now % 10 - 1) +    que.append(now * 10 + now % 10) +    if now % 10 != 9: +        que.append(now * 10 + now % 10 + 1)