import sys

import heapq

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



def main():

    K = int(eval(input()))

    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    heapq.heapify(q)

    while len(q) < K:

        K -= len(q)

        new_q = []

        for i in q:

            d1 = int(str(i)[-1])

            if d1 > 0:

                new_q.append(i * 10 + d1 - 1)

            new_q.append(i * 10 + d1)

            if d1 < 9:

                new_q.append(i * 10 + d1 + 1)

        q = new_q

        heapq.heapify(q)

    print((q[K-1]))



if __name__ == '__main__':

    main()

import sys

import heapq

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



def main():

    K = int(eval(input()))

    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    heapq.heapify(q)

    while len(q) < K:

        K -= len(q)

        new_q = []

        for i in q:

            d1 = i % 10

            if d1 > 0:

                new_q.append(i * 10 + d1 - 1)

            new_q.append(i * 10 + d1)

            if d1 < 9:

                new_q.append(i * 10 + d1 + 1)

        q = new_q

        heapq.heapify(q)

    print((q[K-1]))



if __name__ == '__main__':

    main()

import sys
import heapq


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


def main():
    K = int(eval(input()))
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    heapq.heapify(q)
    while len(q) < K:
        K -= len(q)
        new_q = []
        for i in q:
            d1 = int(str(i)[-1])
            if d1 > 0:
                new_q.append(i * 10 + d1 - 1)
            new_q.append(i * 10 + d1)
            if d1 < 9:
                new_q.append(i * 10 + d1 + 1)
        q = new_q
        heapq.heapify(q)
    print((q[K - 1]))


if __name__ == "__main__":
    main()

import sys
import heapq


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


def main():
    K = int(eval(input()))
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    heapq.heapify(q)
    while len(q) < K:
        K -= len(q)
        new_q = []
        for i in q:
            d1 = i % 10
            if d1 > 0:
                new_q.append(i * 10 + d1 - 1)
            new_q.append(i * 10 + d1)
            if d1 < 9:
                new_q.append(i * 10 + d1 + 1)
        q = new_q
        heapq.heapify(q)
    print((q[K - 1]))


if __name__ == "__main__":
    main()

-            d1 = int(str(i)[-1]) +            d1 = i % 10