import queue



k = int(eval(input()))

q = queue.Queue()



for i in range(1,10):

    q.put(i)



for i in range(1,k):

    l = q.get()

    m = l % 10

    if (m != 0):

        q.put(l * 10 + m - 1)

    q.put(l * 10 + m)

    if (m != 9):

        q.put(l * 10 + m + 1)



print((q.get())) 
from collections import deque



k = int(eval(input()))

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



for i in range(1,k):

    l = q.popleft()

    if (len(q) < k):

        m = l % 10

        if (m != 0):

            q.append(l * 10 + m - 1)

        q.append(l * 10 + m)

        if (m != 9):

            q.append(l * 10 + m + 1)



print((q.popleft()))
import queue

k = int(eval(input()))
q = queue.Queue()
for i in range(1, 10):
    q.put(i)
for i in range(1, k):
    l = q.get()
    m = l % 10
    if m != 0:
        q.put(l * 10 + m - 1)
    q.put(l * 10 + m)
    if m != 9:
        q.put(l * 10 + m + 1)
print((q.get()))

from collections import deque

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

-import queue +from collections import deque -q = queue.Queue() -for i in range(1, 10): -    q.put(i) +q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -    l = q.get() -    m = l % 10 -    if m != 0: -        q.put(l * 10 + m - 1) -    q.put(l * 10 + m) -    if m != 9: -        q.put(l * 10 + m + 1) -print((q.get())) +    l = q.popleft() +    if len(q) < k: +        m = l % 10 +        if m != 0: +            q.append(l * 10 + m - 1) +        q.append(l * 10 + m) +        if m != 9: +            q.append(l * 10 + m + 1) +print((q.popleft()))