import queue

K = int(eval(input()))

q = queue.Queue()

for i in range(1,10):

    q.put(i)



for i in range(K):

    x = q.get()

    a = x%10

    if a !=0:

        q.put(10*x +a -1)

    q.put(10*x +a )

    if a != 9:

        q.put(10*x +a +1)

print(x)
def main():

    import sys

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

    k = int(eval(input()))

    from collections import deque

    que = deque(list(range(1, 10)))

    for i in range(k):

        now = que.popleft()

        r = now%10

        nx = now*10

        if r == 0:

            for j in [0, 1]:

                que.append(nx+r+j)

        elif r == 9:

            for j in [-1, 0]:

                que.append(nx+r+j)

        else:

            for j in [-1, 0, 1]:

                que.append(nx+r+j)

    print(now)



if __name__ == '__main__':

    main()
import queue

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

def main():
    import sys

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

    k = int(eval(input()))
    from collections import deque

    que = deque(list(range(1, 10)))
    for i in range(k):
        now = que.popleft()
        r = now % 10
        nx = now * 10
        if r == 0:
            for j in [0, 1]:
                que.append(nx + r + j)
        elif r == 9:
            for j in [-1, 0]:
                que.append(nx + r + j)
        else:
            for j in [-1, 0, 1]:
                que.append(nx + r + j)
    print(now)


if __name__ == "__main__":
    main()

-import queue +def main(): +    import sys -K = int(eval(input())) -q = queue.Queue() -for i in range(1, 10): -    q.put(i) -for i in range(K): -    x = q.get() -    a = x % 10 -    if a != 0: -        q.put(10 * x + a - 1) -    q.put(10 * x + a) -    if a != 9: -        q.put(10 * x + a + 1) -print(x) +    def input(): +        return sys.stdin.readline().rstrip() + +    k = int(eval(input())) +    from collections import deque + +    que = deque(list(range(1, 10))) +    for i in range(k): +        now = que.popleft() +        r = now % 10 +        nx = now * 10 +        if r == 0: +            for j in [0, 1]: +                que.append(nx + r + j) +        elif r == 9: +            for j in [-1, 0]: +                que.append(nx + r + j) +        else: +            for j in [-1, 0, 1]: +                que.append(nx + r + j) +    print(now) + + +if __name__ == "__main__": +    main()