# D - Lunlun Number



K = int(eval(input()))

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

i = 0

while len(stack) < K:

    first = int(str(stack[i])[-1:])

    if first == 0:

        stack.append(int(str(stack[i]) + str(first)))

        stack.append(int(str(stack[i]) + str(first + 1)))

    elif first == 9:

        stack.append(int(str(stack[i]) + str(first - 1)))

        stack.append(int(str(stack[i]) + str(first)))

    else:

        stack.append(int(str(stack[i]) + str(first - 1)))

        stack.append(int(str(stack[i]) + str(first)))

        stack.append(int(str(stack[i]) + str(first + 1)))        

    i += 1



print((stack[K - 1]))
# D - Lunlun Number



K = int(eval(input()))



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

i = 0



while len(N) < K:

    n = int(str(N[i]) + str(N[i])[-1:])

    if str(n)[-1:] == '0':

        N += [n, n + 1]

    elif str(n)[-1:] == '9':

        N += [n - 1, n]

    else:

        N += [n - 1, n, n + 1]

    i += 1



print((N[K - 1]))
# D - Lunlun Number
K = int(eval(input()))
stack = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0
while len(stack) < K:
    first = int(str(stack[i])[-1:])
    if first == 0:
        stack.append(int(str(stack[i]) + str(first)))
        stack.append(int(str(stack[i]) + str(first + 1)))
    elif first == 9:
        stack.append(int(str(stack[i]) + str(first - 1)))
        stack.append(int(str(stack[i]) + str(first)))
    else:
        stack.append(int(str(stack[i]) + str(first - 1)))
        stack.append(int(str(stack[i]) + str(first)))
        stack.append(int(str(stack[i]) + str(first + 1)))
    i += 1
print((stack[K - 1]))

# D - Lunlun Number
K = int(eval(input()))
N = [1, 2, 3, 4, 5, 6, 7, 8, 9]
i = 0
while len(N) < K:
    n = int(str(N[i]) + str(N[i])[-1:])
    if str(n)[-1:] == "0":
        N += [n, n + 1]
    elif str(n)[-1:] == "9":
        N += [n - 1, n]
    else:
        N += [n - 1, n, n + 1]
    i += 1
print((N[K - 1]))

-stack = [1, 2, 3, 4, 5, 6, 7, 8, 9] +N = [1, 2, 3, 4, 5, 6, 7, 8, 9] -while len(stack) < K: -    first = int(str(stack[i])[-1:]) -    if first == 0: -        stack.append(int(str(stack[i]) + str(first))) -        stack.append(int(str(stack[i]) + str(first + 1))) -    elif first == 9: -        stack.append(int(str(stack[i]) + str(first - 1))) -        stack.append(int(str(stack[i]) + str(first))) +while len(N) < K: +    n = int(str(N[i]) + str(N[i])[-1:]) +    if str(n)[-1:] == "0": +        N += [n, n + 1] +    elif str(n)[-1:] == "9": +        N += [n - 1, n] -        stack.append(int(str(stack[i]) + str(first - 1))) -        stack.append(int(str(stack[i]) + str(first))) -        stack.append(int(str(stack[i]) + str(first + 1))) +        N += [n - 1, n, n + 1] -print((stack[K - 1])) +print((N[K - 1]))