import sys





def input():

    return sys.stdin.readline().strip()





def main():

    K = int(eval(input()))

    ans = list("123456789")

    tmp = ans.copy()

    while True:

        tmp2 = []

        for t in tmp:

            for i in range(int(t[-1]) - 1, int(t[-1]) + 2):

                if 0 <= i < 10:

                    tmp2.append(t + str(i))

        tmp = tmp2.copy()

        ans += tmp

        if len(ans) >= K:

            break



    print((ans[K - 1]))





if __name__ == "__main__":

    main()

import collections

import sys





def input():

    return sys.stdin.readline().strip()





def bfs(K):

    q = collections.deque(list("123456789"))

    ans = list("123456789")

    while len(ans) < K:

        n = q.popleft()

        for i in range(int(n[-1]) - 1, int(n[-1]) + 2):

            if 0 <= i < 10:

                q.append(n + str(i))

                ans.append(n + str(i))



    return ans[K - 1]





def main():

    K = int(eval(input()))

    print((bfs(K)))





if __name__ == "__main__":

    main()

import sys


def input():
    return sys.stdin.readline().strip()


def main():
    K = int(eval(input()))
    ans = list("123456789")
    tmp = ans.copy()
    while True:
        tmp2 = []
        for t in tmp:
            for i in range(int(t[-1]) - 1, int(t[-1]) + 2):
                if 0 <= i < 10:
                    tmp2.append(t + str(i))
        tmp = tmp2.copy()
        ans += tmp
        if len(ans) >= K:
            break
    print((ans[K - 1]))


if __name__ == "__main__":
    main()

import collections
import sys


def input():
    return sys.stdin.readline().strip()


def bfs(K):
    q = collections.deque(list("123456789"))
    ans = list("123456789")
    while len(ans) < K:
        n = q.popleft()
        for i in range(int(n[-1]) - 1, int(n[-1]) + 2):
            if 0 <= i < 10:
                q.append(n + str(i))
                ans.append(n + str(i))
    return ans[K - 1]


def main():
    K = int(eval(input()))
    print((bfs(K)))


if __name__ == "__main__":
    main()

+import collections +def bfs(K): +    q = collections.deque(list("123456789")) +    ans = list("123456789") +    while len(ans) < K: +        n = q.popleft() +        for i in range(int(n[-1]) - 1, int(n[-1]) + 2): +            if 0 <= i < 10: +                q.append(n + str(i)) +                ans.append(n + str(i)) +    return ans[K - 1] + + -    ans = list("123456789") -    tmp = ans.copy() -    while True: -        tmp2 = [] -        for t in tmp: -            for i in range(int(t[-1]) - 1, int(t[-1]) + 2): -                if 0 <= i < 10: -                    tmp2.append(t + str(i)) -        tmp = tmp2.copy() -        ans += tmp -        if len(ans) >= K: -            break -    print((ans[K - 1])) +    print((bfs(K)))