def func(n):

    s = str(n)

    L = len(s)

    for i in reversed(list(range(L-1))):

        x = int(s[i])

        y = int(s[i+1])

        if abs(x-y) > 1:

            buf = 10**(L-(i+1)-1)

            if x > y:

                return int(s[:i] + str(x) + str(x-1)) * buf

            else:

                return (int(s[:i+1]) + 1)*(buf*10)

    return -1



def main():

    k = int(eval(input()))

    target = 1

    while k > 0:

        buf = func(target)

        if buf == -1:

            k -= 1

            if k == 0:

                break

            target += 1

        else:

            target = buf

#        print(target)

    print(target)



if __name__ == "__main__":

    main()
import queue



def main():

    k = int(eval(input()))

    q = queue.Queue()

    for i in range(1, 10):

        q.put(str(i))

    ans = ""

    for i in range(1, k+1):

        ans = q.get()

        if i < k:

            p = int(ans[-1])

            if p == 0:

                q.put(ans + "0")

                q.put(ans + "1")

            elif p == 9:

                q.put(ans + "8")

                q.put(ans + "9")

            else:

                for v in range(p-1, p+2):

                    q.put(ans + str(v))

    print(ans)



if __name__ == "__main__":

    main()
def func(n):
    s = str(n)
    L = len(s)
    for i in reversed(list(range(L - 1))):
        x = int(s[i])
        y = int(s[i + 1])
        if abs(x - y) > 1:
            buf = 10 ** (L - (i + 1) - 1)
            if x > y:
                return int(s[:i] + str(x) + str(x - 1)) * buf
            else:
                return (int(s[: i + 1]) + 1) * (buf * 10)
    return -1


def main():
    k = int(eval(input()))
    target = 1
    while k > 0:
        buf = func(target)
        if buf == -1:
            k -= 1
            if k == 0:
                break
            target += 1
        else:
            target = buf
    #        print(target)
    print(target)


if __name__ == "__main__":
    main()

import queue


def main():
    k = int(eval(input()))
    q = queue.Queue()
    for i in range(1, 10):
        q.put(str(i))
    ans = ""
    for i in range(1, k + 1):
        ans = q.get()
        if i < k:
            p = int(ans[-1])
            if p == 0:
                q.put(ans + "0")
                q.put(ans + "1")
            elif p == 9:
                q.put(ans + "8")
                q.put(ans + "9")
            else:
                for v in range(p - 1, p + 2):
                    q.put(ans + str(v))
    print(ans)


if __name__ == "__main__":
    main()

-def func(n): -    s = str(n) -    L = len(s) -    for i in reversed(list(range(L - 1))): -        x = int(s[i]) -        y = int(s[i + 1]) -        if abs(x - y) > 1: -            buf = 10 ** (L - (i + 1) - 1) -            if x > y: -                return int(s[:i] + str(x) + str(x - 1)) * buf -            else: -                return (int(s[: i + 1]) + 1) * (buf * 10) -    return -1 +import queue -    target = 1 -    while k > 0: -        buf = func(target) -        if buf == -1: -            k -= 1 -            if k == 0: -                break -            target += 1 -        else: -            target = buf -    #        print(target) -    print(target) +    q = queue.Queue() +    for i in range(1, 10): +        q.put(str(i)) +    ans = "" +    for i in range(1, k + 1): +        ans = q.get() +        if i < k: +            p = int(ans[-1]) +            if p == 0: +                q.put(ans + "0") +                q.put(ans + "1") +            elif p == 9: +                q.put(ans + "8") +                q.put(ans + "9") +            else: +                for v in range(p - 1, p + 2): +                    q.put(ans + str(v)) +    print(ans)