# 解説放送

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)
# 解説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)
# 解説放送
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)

# 解説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)

-# 解説放送 +# 解説PDF +from collections import deque + -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) +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)