from heapq import heappop, heappush, heapify

K = int(eval(input()))

M = K



que = list(range(1, 10))

V = set()

heapify(que)



while M + 100 >= 0:

    top = heappop(que)

    if top in V:

        continue

    V.add(top)

    M -= 1



    top = str(top)

    L = int(top[0])

    R = int(top[-1])



    for i in (L - 1, L, L + 1):

        if 1 <= i <= 9:

            heappush(que, int(str(i) + top))

    for i in (R - 1, R, R + 1):

        if 0 <= i <= 9:

            heappush(que, int(top + str(i)))



V = [int(d) for d in V]

V.sort()

print((V[K - 1]))

from collections import deque

K = int(eval(input()))



que = deque(list(map(str, list(range(1, 10)))))

while K > 1:

    n = que.popleft()

    K -= 1

    R = int(n[-1])

    for r in (R - 1, R, R + 1):

        if 0 <= r <= 9:

            que.append(n + str(r))



print((que[0]))

from heapq import heappop, heappush, heapify

K = int(eval(input()))
M = K
que = list(range(1, 10))
V = set()
heapify(que)
while M + 100 >= 0:
    top = heappop(que)
    if top in V:
        continue
    V.add(top)
    M -= 1
    top = str(top)
    L = int(top[0])
    R = int(top[-1])
    for i in (L - 1, L, L + 1):
        if 1 <= i <= 9:
            heappush(que, int(str(i) + top))
    for i in (R - 1, R, R + 1):
        if 0 <= i <= 9:
            heappush(que, int(top + str(i)))
V = [int(d) for d in V]
V.sort()
print((V[K - 1]))

from collections import deque

K = int(eval(input()))
que = deque(list(map(str, list(range(1, 10)))))
while K > 1:
    n = que.popleft()
    K -= 1
    R = int(n[-1])
    for r in (R - 1, R, R + 1):
        if 0 <= r <= 9:
            que.append(n + str(r))
print((que[0]))

-from heapq import heappop, heappush, heapify +from collections import deque -M = K -que = list(range(1, 10)) -V = set() -heapify(que) -while M + 100 >= 0: -    top = heappop(que) -    if top in V: -        continue -    V.add(top) -    M -= 1 -    top = str(top) -    L = int(top[0]) -    R = int(top[-1]) -    for i in (L - 1, L, L + 1): -        if 1 <= i <= 9: -            heappush(que, int(str(i) + top)) -    for i in (R - 1, R, R + 1): -        if 0 <= i <= 9: -            heappush(que, int(top + str(i))) -V = [int(d) for d in V] -V.sort() -print((V[K - 1])) +que = deque(list(map(str, list(range(1, 10))))) +while K > 1: +    n = que.popleft() +    K -= 1 +    R = int(n[-1]) +    for r in (R - 1, R, R + 1): +        if 0 <= r <= 9: +            que.append(n + str(r)) +print((que[0]))