import heapq



K = int(eval(input()))



Q = [1,2,3,4,5,6,7,8,9]

heapq.heapify(Q)



for i in range(K-1):

    x = heapq.heappop(Q)

    if x % 10 != 0:

        heapq.heappush(Q,10*x+x%10-1)

    heapq.heappush(Q,10*x+x%10)

    if x % 10 != 9:

        heapq.heappush(Q,10*x+x%10+1)



print((heapq.heappop(Q)))
from collections import deque



K = int(eval(input()))



Q = deque([1,2,3,4,5,6,7,8,9])



for i in range(K-1):

    x = Q.popleft()

    if x % 10 != 0:

        Q.append(10*x+x%10-1)

    Q.append(10*x+x%10)

    if x % 10 != 9:

        Q.append(10*x+x%10+1)



print((Q.popleft()))
import heapq

K = int(eval(input()))
Q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapq.heapify(Q)
for i in range(K - 1):
    x = heapq.heappop(Q)
    if x % 10 != 0:
        heapq.heappush(Q, 10 * x + x % 10 - 1)
    heapq.heappush(Q, 10 * x + x % 10)
    if x % 10 != 9:
        heapq.heappush(Q, 10 * x + x % 10 + 1)
print((heapq.heappop(Q)))

from collections import deque

K = int(eval(input()))
Q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K - 1):
    x = Q.popleft()
    if x % 10 != 0:
        Q.append(10 * x + x % 10 - 1)
    Q.append(10 * x + x % 10)
    if x % 10 != 9:
        Q.append(10 * x + x % 10 + 1)
print((Q.popleft()))

-import heapq +from collections import deque -Q = [1, 2, 3, 4, 5, 6, 7, 8, 9] -heapq.heapify(Q) +Q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -    x = heapq.heappop(Q) +    x = Q.popleft() -        heapq.heappush(Q, 10 * x + x % 10 - 1) -    heapq.heappush(Q, 10 * x + x % 10) +        Q.append(10 * x + x % 10 - 1) +    Q.append(10 * x + x % 10) -        heapq.heappush(Q, 10 * x + x % 10 + 1) -print((heapq.heappop(Q))) +        Q.append(10 * x + x % 10 + 1) +print((Q.popleft()))