from itertools import product

K = int(eval(input()))

ans = []



for l in range(10):

    for s in range(1, 10):

        for pattern in product([0, 1, 2], repeat=l):  # そのまま, １つ上, １つ下

            X = [s]

            for p in pattern:

                if X[-1] == 0 and p == 2:

                    break

                if X[-1] == 9 and p == 1:

                    break



                if p == 0:

                    X.append(X[-1])



                if p == 1:

                    X.append(X[-1] + 1)



                if p == 2:

                    X.append(X[-1] - 1)

            else:

                ans.append(int(''.join(map(str, X))))



ans.sort()

print((ans[K - 1]))

from itertools import product

K = int(eval(input()))



ans = []

for l in range(10):

    for s in range(1, 10):

        for pattern in product([-1, 0, 1], repeat=l):

            X = [s]

            for p in pattern:

                if not (0 <= X[-1] + p <= 9):

                    break

                X.append(X[-1] + p)

            else:

                ans.append(int(''.join(map(str, X))))



ans.sort()

print((ans[K - 1]))

from itertools import product

K = int(eval(input()))
ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([0, 1, 2], repeat=l):  # そのまま, １つ上, １つ下
            X = [s]
            for p in pattern:
                if X[-1] == 0 and p == 2:
                    break
                if X[-1] == 9 and p == 1:
                    break
                if p == 0:
                    X.append(X[-1])
                if p == 1:
                    X.append(X[-1] + 1)
                if p == 2:
                    X.append(X[-1] - 1)
            else:
                ans.append(int("".join(map(str, X))))
ans.sort()
print((ans[K - 1]))

from itertools import product

K = int(eval(input()))
ans = []
for l in range(10):
    for s in range(1, 10):
        for pattern in product([-1, 0, 1], repeat=l):
            X = [s]
            for p in pattern:
                if not (0 <= X[-1] + p <= 9):
                    break
                X.append(X[-1] + p)
            else:
                ans.append(int("".join(map(str, X))))
ans.sort()
print((ans[K - 1]))

-        for pattern in product([0, 1, 2], repeat=l):  # そのまま, １つ上, １つ下 +        for pattern in product([-1, 0, 1], repeat=l): -                if X[-1] == 0 and p == 2: +                if not (0 <= X[-1] + p <= 9): -                if X[-1] == 9 and p == 1: -                    break -                if p == 0: -                    X.append(X[-1]) -                if p == 1: -                    X.append(X[-1] + 1) -                if p == 2: -                    X.append(X[-1] - 1) +                X.append(X[-1] + p)