import sys



sys.setrecursionlimit(10 ** 5)





def dfs(v):

    ans.append(v)

    if v > 1_000_000_000:

        return

    for d in range(10):

        if abs(d - v % 10) <= 1:

            nv = v * 10 + d

            dfs(nv)





K = int(eval(input()))

ans = []

[dfs(i) for i in range(1, 10)]

print((sorted(ans)[K - 1]))

import sys



sys.setrecursionlimit(10 ** 5)





def dfs(v):

    if v > 3234566667:

        return

    ans.append(v)

    d = v % 10

    if d - 1 >= 0:

        dfs(v * 10 + d - 1)

    dfs(v * 10 + d)

    if d + 1 < 10:

        dfs(v * 10 + d + 1)





K = int(eval(input()))

ans = []

[dfs(i) for i in range(1, 10)]

print((sorted(ans)[K - 1]))

import sys

sys.setrecursionlimit(10**5)


def dfs(v):
    ans.append(v)
    if v > 1_000_000_000:
        return
    for d in range(10):
        if abs(d - v % 10) <= 1:
            nv = v * 10 + d
            dfs(nv)


K = int(eval(input()))
ans = []
[dfs(i) for i in range(1, 10)]
print((sorted(ans)[K - 1]))

import sys

sys.setrecursionlimit(10**5)


def dfs(v):
    if v > 3234566667:
        return
    ans.append(v)
    d = v % 10
    if d - 1 >= 0:
        dfs(v * 10 + d - 1)
    dfs(v * 10 + d)
    if d + 1 < 10:
        dfs(v * 10 + d + 1)


K = int(eval(input()))
ans = []
[dfs(i) for i in range(1, 10)]
print((sorted(ans)[K - 1]))

+    if v > 3234566667: +        return -    if v > 1_000_000_000: -        return -    for d in range(10): -        if abs(d - v % 10) <= 1: -            nv = v * 10 + d -            dfs(nv) +    d = v % 10 +    if d - 1 >= 0: +        dfs(v * 10 + d - 1) +    dfs(v * 10 + d) +    if d + 1 < 10: +        dfs(v * 10 + d + 1)