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

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

-from collections import deque +K = int(eval(input())) +import copy -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) +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]))