import sys

input = sys.stdin.readline

sys.setrecursionlimit(2147483647)

def f(v,i,ans):

    if i == 0:return

    if str(v)[-1] != "0":

        x = int(str(v)+str(int(str(v)[-1])-1))

        ans.add(x)

        f(x,i-1,ans)

    y = int(str(v)+str(v)[-1])

    ans.add(y)

    f(y,i-1,ans)

    if str(v)[-1] != "9":

        z = int(str(v)+str(int(str(v)[-1])+1))

        ans.add(z)

        f(z,i-1,ans)

def main():

    K = int(eval(input()))

    ans = set()

    for i in range(1,10):

        ans.add(i)

        f(i,10,ans)

    ans = list(ans)

    ans.sort()

    print((ans[K-1]))

if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline

from collections import deque

def main():

    K = int(eval(input()))

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

    if K <= 9:

        print((que[K-1]))

    else:

        K -= 9

        while K >= 0:

            v = que.popleft()

            if v[-1] != "0":

                K -= 1

                v1 = v + str(int(v[-1])-1)

                if K == 0:

                    print(v1)

                    break

                que.append(v1)

            K -= 1

            v2 = v + v[-1]

            if K == 0:

                print(v2)

                break

            que.append(v2)

            if v[-1] != "9":

                K -= 1

                v3 = v + str(int(v[-1])+1)

                if K == 0:

                    print(v3)

                    break

                que.append(v3)

if __name__ == "__main__":

    main()
import sys

input = sys.stdin.readline
sys.setrecursionlimit(2147483647)


def f(v, i, ans):
    if i == 0:
        return
    if str(v)[-1] != "0":
        x = int(str(v) + str(int(str(v)[-1]) - 1))
        ans.add(x)
        f(x, i - 1, ans)
    y = int(str(v) + str(v)[-1])
    ans.add(y)
    f(y, i - 1, ans)
    if str(v)[-1] != "9":
        z = int(str(v) + str(int(str(v)[-1]) + 1))
        ans.add(z)
        f(z, i - 1, ans)


def main():
    K = int(eval(input()))
    ans = set()
    for i in range(1, 10):
        ans.add(i)
        f(i, 10, ans)
    ans = list(ans)
    ans.sort()
    print((ans[K - 1]))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
from collections import deque


def main():
    K = int(eval(input()))
    que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
    if K <= 9:
        print((que[K - 1]))
    else:
        K -= 9
        while K >= 0:
            v = que.popleft()
            if v[-1] != "0":
                K -= 1
                v1 = v + str(int(v[-1]) - 1)
                if K == 0:
                    print(v1)
                    break
                que.append(v1)
            K -= 1
            v2 = v + v[-1]
            if K == 0:
                print(v2)
                break
            que.append(v2)
            if v[-1] != "9":
                K -= 1
                v3 = v + str(int(v[-1]) + 1)
                if K == 0:
                    print(v3)
                    break
                que.append(v3)


if __name__ == "__main__":
    main()

-sys.setrecursionlimit(2147483647) - - -def f(v, i, ans): -    if i == 0: -        return -    if str(v)[-1] != "0": -        x = int(str(v) + str(int(str(v)[-1]) - 1)) -        ans.add(x) -        f(x, i - 1, ans) -    y = int(str(v) + str(v)[-1]) -    ans.add(y) -    f(y, i - 1, ans) -    if str(v)[-1] != "9": -        z = int(str(v) + str(int(str(v)[-1]) + 1)) -        ans.add(z) -        f(z, i - 1, ans) +from collections import deque -    ans = set() -    for i in range(1, 10): -        ans.add(i) -        f(i, 10, ans) -    ans = list(ans) -    ans.sort() -    print((ans[K - 1])) +    que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) +    if K <= 9: +        print((que[K - 1])) +    else: +        K -= 9 +        while K >= 0: +            v = que.popleft() +            if v[-1] != "0": +                K -= 1 +                v1 = v + str(int(v[-1]) - 1) +                if K == 0: +                    print(v1) +                    break +                que.append(v1) +            K -= 1 +            v2 = v + v[-1] +            if K == 0: +                print(v2) +                break +            que.append(v2) +            if v[-1] != "9": +                K -= 1 +                v3 = v + str(int(v[-1]) + 1) +                if K == 0: +                    print(v3) +                    break +                que.append(v3)