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

from collections import deque

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



def main():

    K = int(eval(input()))

    q = deque()

    for i in range(1, 10):

        if K == 1:

            print(i)

            exit()

        K -= 1

        q.append(i)

    while q:

        v = q.popleft()

        sv = v % 10

        for i in (-1, 0, 1):

            if 0 <= sv + i < 10:

                if K == 1:

                    print((v * 10 + sv + i))

                    exit()

                K -= 1

                q.append(v * 10 + sv + i)



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
from collections import deque


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


def main():
    K = int(eval(input()))
    q = deque()
    for i in range(1, 10):
        if K == 1:
            print(i)
            exit()
        K -= 1
        q.append(i)
    while q:
        v = q.popleft()
        sv = v % 10
        for i in (-1, 0, 1):
            if 0 <= sv + i < 10:
                if K == 1:
                    print((v * 10 + sv + i))
                    exit()
                K -= 1
                q.append(v * 10 + sv + i)


if __name__ == "__main__":
    main()

-import heapq +from collections import deque -    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])) +    q = deque() +    for i in range(1, 10): +        if K == 1: +            print(i) +            exit() +        K -= 1 +        q.append(i) +    while q: +        v = q.popleft() +        sv = v % 10 +        for i in (-1, 0, 1): +            if 0 <= sv + i < 10: +                if K == 1: +                    print((v * 10 + sv + i)) +                    exit() +                K -= 1 +                q.append(v * 10 + sv + i)