import queue



N = int(eval(input()))

q = queue.Queue()

for i in range(1, 10):

    q.put(i)



ans = 0

for i in range(N):

    ans = q.get()

    m = ans % 10

    if ans % 10 != 0:

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

    q.put(ans * 10 + m)

    if ans % 10 != 9:

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



print(ans)
import sys

sys.setrecursionlimit(10**6)



def dfs(n):

    if n > 3234566667:

        return

    ans.append(n)

    if n % 10 != 0:

        dfs(n * 10 + (n % 10) - 1)

    dfs(n * 10 + (n % 10))

    if n % 10 != 9:

        dfs(n * 10 + (n % 10) + 1)



N = int(eval(input()))

ans = []

for i in range(1, 10):

    dfs(i)

ans.sort()

print((ans[N - 1]))
import queue

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

import sys

sys.setrecursionlimit(10**6)


def dfs(n):
    if n > 3234566667:
        return
    ans.append(n)
    if n % 10 != 0:
        dfs(n * 10 + (n % 10) - 1)
    dfs(n * 10 + (n % 10))
    if n % 10 != 9:
        dfs(n * 10 + (n % 10) + 1)


N = int(eval(input()))
ans = []
for i in range(1, 10):
    dfs(i)
ans.sort()
print((ans[N - 1]))

-import queue +import sys + +sys.setrecursionlimit(10**6) + + +def dfs(n): +    if n > 3234566667: +        return +    ans.append(n) +    if n % 10 != 0: +        dfs(n * 10 + (n % 10) - 1) +    dfs(n * 10 + (n % 10)) +    if n % 10 != 9: +        dfs(n * 10 + (n % 10) + 1) + -q = queue.Queue() +ans = [] -    q.put(i) -ans = 0 -for i in range(N): -    ans = q.get() -    m = ans % 10 -    if ans % 10 != 0: -        q.put(ans * 10 + m - 1) -    q.put(ans * 10 + m) -    if ans % 10 != 9: -        q.put(ans * 10 + m + 1) -print(ans) +    dfs(i) +ans.sort() +print((ans[N - 1]))