from collections import deque

k = int(eval(input()))

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



ans = []

while len(ans) < k:

    a = d.popleft()

    ans.append(a)

    l = [a%10-1, a%10, a%10+1]

    for i in l:

        if i==-1 or i==10:

            continue

        d.append(a*10 + i)



print((ans[k-1]))
from collections import deque

k = int(eval(input()))

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



for i in range(k):

    a = d.popleft()

    l = [a%10-1, a%10, a%10+1]

    for j in l:

        if j==-1 or j==10:

            continue

        d.append(a*10 + j)



print(a)
from collections import deque

k = int(eval(input()))
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
ans = []
while len(ans) < k:
    a = d.popleft()
    ans.append(a)
    l = [a % 10 - 1, a % 10, a % 10 + 1]
    for i in l:
        if i == -1 or i == 10:
            continue
        d.append(a * 10 + i)
print((ans[k - 1]))

from collections import deque

k = int(eval(input()))
d = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(k):
    a = d.popleft()
    l = [a % 10 - 1, a % 10, a % 10 + 1]
    for j in l:
        if j == -1 or j == 10:
            continue
        d.append(a * 10 + j)
print(a)

-ans = [] -while len(ans) < k: +for i in range(k): -    ans.append(a) -    for i in l: -        if i == -1 or i == 10: +    for j in l: +        if j == -1 or j == 10: -        d.append(a * 10 + i) -print((ans[k - 1])) +        d.append(a * 10 + j) +print(a)