K = int(eval(input()))



V = [1, 2, 3, 4, 5, 6, 7, 8, 9]



for i in range (0, 100000):

	if V[i]%10 == 0:

		V.append(10*V[i]+0)

		V.append(10*V[i]+1)

	elif V[i]%10 == 9:

		V.append(10*V[i]+8)

		V.append(10*V[i]+9)

	else:

		V.append(10*V[i]+V[i]%10-1)

		V.append(10*V[i]+V[i]%10)

		V.append(10*V[i]+V[i]%10+1)



print((V[K-1]))
import collections



K = int(eval(input()))



L = [1,2,3,4,5,6,7,8,9]

Q = collections.deque(L)

count = 0 



while count < K-1:

    V = Q.popleft()

    count+=1

    if V%10 == 0:

        Q.append(10*V)

        Q.append(10*V+1)

    elif V%10 == 9:

        Q.append(10*V+8)

        Q.append(10*V+9)

    else:

        Q.append(10*V+(V%10)-1)

        Q.append(10*V+(V%10))

        Q.append(10*V+(V%10)+1)



print((Q.popleft()))
K = int(eval(input()))
V = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(0, 100000):
    if V[i] % 10 == 0:
        V.append(10 * V[i] + 0)
        V.append(10 * V[i] + 1)
    elif V[i] % 10 == 9:
        V.append(10 * V[i] + 8)
        V.append(10 * V[i] + 9)
    else:
        V.append(10 * V[i] + V[i] % 10 - 1)
        V.append(10 * V[i] + V[i] % 10)
        V.append(10 * V[i] + V[i] % 10 + 1)
print((V[K - 1]))

import collections

K = int(eval(input()))
L = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Q = collections.deque(L)
count = 0
while count < K - 1:
    V = Q.popleft()
    count += 1
    if V % 10 == 0:
        Q.append(10 * V)
        Q.append(10 * V + 1)
    elif V % 10 == 9:
        Q.append(10 * V + 8)
        Q.append(10 * V + 9)
    else:
        Q.append(10 * V + (V % 10) - 1)
        Q.append(10 * V + (V % 10))
        Q.append(10 * V + (V % 10) + 1)
print((Q.popleft()))

+import collections + -V = [1, 2, 3, 4, 5, 6, 7, 8, 9] -for i in range(0, 100000): -    if V[i] % 10 == 0: -        V.append(10 * V[i] + 0) -        V.append(10 * V[i] + 1) -    elif V[i] % 10 == 9: -        V.append(10 * V[i] + 8) -        V.append(10 * V[i] + 9) +L = [1, 2, 3, 4, 5, 6, 7, 8, 9] +Q = collections.deque(L) +count = 0 +while count < K - 1: +    V = Q.popleft() +    count += 1 +    if V % 10 == 0: +        Q.append(10 * V) +        Q.append(10 * V + 1) +    elif V % 10 == 9: +        Q.append(10 * V + 8) +        Q.append(10 * V + 9) -        V.append(10 * V[i] + V[i] % 10 - 1) -        V.append(10 * V[i] + V[i] % 10) -        V.append(10 * V[i] + V[i] % 10 + 1) -print((V[K - 1])) +        Q.append(10 * V + (V % 10) - 1) +        Q.append(10 * V + (V % 10)) +        Q.append(10 * V + (V % 10) + 1) +print((Q.popleft()))