from collections import deque



from heapq import heappush, heappop





def main():

    K = int(eval(input()))



    q = []



    for i in range(1, 10):

        heappush(q, i)



    while True:

        v = heappop(q)

        K -= 1

        if K == 0:

            print(v)

            exit()

        u = v % 10

        nv = v * 10 + u



        heappush(q, nv)

        if u == 0:

            heappush(q, nv + 1)

        elif u == 9:

            heappush(q, nv - 1)

        else:

            heappush(q, nv - 1)

            heappush(q, nv + 1)





main()

from collections import deque



from collections import deque





def main():

    K = int(eval(input()))



    q = deque()



    for i in range(1, 10):

        q.append(i)



    while True:

        v = q.popleft()

        K -= 1

        if K == 0:

            print(v)

            exit()

        u = v % 10

        nv = v * 10 + u



        if u == 0:

            q.append(nv)

            q.append(nv + 1)

        elif u == 9:

            q.append(nv - 1)

            q.append(nv)

        else:

            q.append(nv - 1)

            q.append(nv)

            q.append(nv + 1)





main()

from collections import deque
from heapq import heappush, heappop


def main():
    K = int(eval(input()))
    q = []
    for i in range(1, 10):
        heappush(q, i)
    while True:
        v = heappop(q)
        K -= 1
        if K == 0:
            print(v)
            exit()
        u = v % 10
        nv = v * 10 + u
        heappush(q, nv)
        if u == 0:
            heappush(q, nv + 1)
        elif u == 9:
            heappush(q, nv - 1)
        else:
            heappush(q, nv - 1)
            heappush(q, nv + 1)


main()

from collections import deque
from collections import deque


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


main()

-from heapq import heappush, heappop +from collections import deque -    q = [] +    q = deque() -        heappush(q, i) +        q.append(i) -        v = heappop(q) +        v = q.popleft() -        heappush(q, nv) -            heappush(q, nv + 1) +            q.append(nv) +            q.append(nv + 1) -            heappush(q, nv - 1) +            q.append(nv - 1) +            q.append(nv) -            heappush(q, nv - 1) -            heappush(q, nv + 1) +            q.append(nv - 1) +            q.append(nv) +            q.append(nv + 1)