from queue import Queue





def solve():



    K = int(eval(input()))



    q = Queue()

    for i in range(9):

        q.put(i+1)

    num = 0

    for i in range(K):

        num = q.get()

        if num % 10 != 0:

            q.put(num*10+num % 10-1)

        q.put(num*10+num % 10)

        if num % 10 != 9:

            q.put(num*10+num % 10+1)

    print(num)





if __name__ == "__main__":

    solve()

from collections import deque





def solve():



    K = int(eval(input()))



    dq = deque()

    # 一桁のケース

    for i in range(9):

        dq.append(i+1)



    for i in range(K):

        num = dq.popleft()

        if num % 10 != 0:

            dq.append(num*10+num % 10-1)

        dq.append(num*10+num % 10)

        if num % 10 != 9:

            dq.append(num*10+num % 10+1)



    print(num)





if __name__ == "__main__":

    solve()

from queue import Queue


def solve():
    K = int(eval(input()))
    q = Queue()
    for i in range(9):
        q.put(i + 1)
    num = 0
    for i in range(K):
        num = q.get()
        if num % 10 != 0:
            q.put(num * 10 + num % 10 - 1)
        q.put(num * 10 + num % 10)
        if num % 10 != 9:
            q.put(num * 10 + num % 10 + 1)
    print(num)


if __name__ == "__main__":
    solve()

from collections import deque


def solve():
    K = int(eval(input()))
    dq = deque()
    # 一桁のケース
    for i in range(9):
        dq.append(i + 1)
    for i in range(K):
        num = dq.popleft()
        if num % 10 != 0:
            dq.append(num * 10 + num % 10 - 1)
        dq.append(num * 10 + num % 10)
        if num % 10 != 9:
            dq.append(num * 10 + num % 10 + 1)
    print(num)


if __name__ == "__main__":
    solve()

-from queue import Queue +from collections import deque -    q = Queue() +    dq = deque() +    # 一桁のケース -        q.put(i + 1) -    num = 0 +        dq.append(i + 1) -        num = q.get() +        num = dq.popleft() -            q.put(num * 10 + num % 10 - 1) -        q.put(num * 10 + num % 10) +            dq.append(num * 10 + num % 10 - 1) +        dq.append(num * 10 + num % 10) -            q.put(num * 10 + num % 10 + 1) +            dq.append(num * 10 + num % 10 + 1)