K = int(eval(input()))



queue = [i for i in range(1, 10)]



for i in range(K - 1):

    N = queue.pop(0)

    if i < K // 2:

        if N % 10 == 0:

            queue.append(N * 10)

            queue.append(N * 10 + 1)

        elif N % 10 == 9:

            queue.append(N * 10 + 8)

            queue.append(N * 10 + 9)

        else:

            queue.append(N * 10 + (N % 10 - 1))

            queue.append(N * 10 + N % 10)

            queue.append(N * 10 + (N % 10 + 1))



print((queue.pop(0)))
K = int(eval(input()))



queue = [i for i in range(1, 10)]



for i in range(K - 1):

    N = queue.pop(0)

    if i < K // 2.5:

        if N % 10 == 0:

            queue.append(N * 10)

            queue.append(N * 10 + 1)

        elif N % 10 == 9:

            queue.append(N * 10 + 8)

            queue.append(N * 10 + 9)

        else:

            queue.append(N * 10 + (N % 10 - 1))

            queue.append(N * 10 + N % 10)

            queue.append(N * 10 + (N % 10 + 1))



print((queue.pop(0)))
K = int(eval(input()))
queue = [i for i in range(1, 10)]
for i in range(K - 1):
    N = queue.pop(0)
    if i < K // 2:
        if N % 10 == 0:
            queue.append(N * 10)
            queue.append(N * 10 + 1)
        elif N % 10 == 9:
            queue.append(N * 10 + 8)
            queue.append(N * 10 + 9)
        else:
            queue.append(N * 10 + (N % 10 - 1))
            queue.append(N * 10 + N % 10)
            queue.append(N * 10 + (N % 10 + 1))
print((queue.pop(0)))

K = int(eval(input()))
queue = [i for i in range(1, 10)]
for i in range(K - 1):
    N = queue.pop(0)
    if i < K // 2.5:
        if N % 10 == 0:
            queue.append(N * 10)
            queue.append(N * 10 + 1)
        elif N % 10 == 9:
            queue.append(N * 10 + 8)
            queue.append(N * 10 + 9)
        else:
            queue.append(N * 10 + (N % 10 - 1))
            queue.append(N * 10 + N % 10)
            queue.append(N * 10 + (N % 10 + 1))
print((queue.pop(0)))

-    if i < K // 2: +    if i < K // 2.5: