k = int(eval(input()))



def hantei(n):

    string = str(n)

    length = len(string)

    ret = True

    for i in range(length-1):

        if abs(int(string[i]) - int(string[i+1])) > 1:

            ret = False

            break

    return ret



lst = [i for i in range(10)]

dic = {}

dic[1] = lst.copy()

keta = 2

while len(lst) < k+1:

    new = []

    for i in range(1, 10):

        tasu = i*(10**(keta-1))

        for j in sorted(dic.keys()):

            temp_lst = dic[j]

            bit = 0

            for youso in temp_lst:

                num = tasu + youso

                if hantei(num):

                    new.append(num)

                    bit = 1

                elif bit == 1:

                    break

    dic[keta] = new.copy()

    lst.extend(new)

    keta += 1



print((lst[k]))
from collections import deque



k = int(eval(input()))



if 1 <= k and k <= 9:

    print(k)

    exit()



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

k -= 9

while k > 0:

    num = d.popleft()

    if num % 10 != 0:

        new = 10*num + (num%10) - 1

        d.append(new)

        k -= 1

        if k == 0: break

    new = 10*num + (num%10)

    d.append(new)

    k -= 1

    if k == 0: break

    if num % 10 != 9:

        new = 10*num + (num%10) + 1

        d.append(new)

        k -= 1

        if k == 0: break



print(new)
k = int(eval(input()))


def hantei(n):
    string = str(n)
    length = len(string)
    ret = True
    for i in range(length - 1):
        if abs(int(string[i]) - int(string[i + 1])) > 1:
            ret = False
            break
    return ret


lst = [i for i in range(10)]
dic = {}
dic[1] = lst.copy()
keta = 2
while len(lst) < k + 1:
    new = []
    for i in range(1, 10):
        tasu = i * (10 ** (keta - 1))
        for j in sorted(dic.keys()):
            temp_lst = dic[j]
            bit = 0
            for youso in temp_lst:
                num = tasu + youso
                if hantei(num):
                    new.append(num)
                    bit = 1
                elif bit == 1:
                    break
    dic[keta] = new.copy()
    lst.extend(new)
    keta += 1
print((lst[k]))

from collections import deque

k = int(eval(input()))
if 1 <= k and k <= 9:
    print(k)
    exit()
d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
    num = d.popleft()
    if num % 10 != 0:
        new = 10 * num + (num % 10) - 1
        d.append(new)
        k -= 1
        if k == 0:
            break
    new = 10 * num + (num % 10)
    d.append(new)
    k -= 1
    if k == 0:
        break
    if num % 10 != 9:
        new = 10 * num + (num % 10) + 1
        d.append(new)
        k -= 1
        if k == 0:
            break
print(new)

+from collections import deque + - - -def hantei(n): -    string = str(n) -    length = len(string) -    ret = True -    for i in range(length - 1): -        if abs(int(string[i]) - int(string[i + 1])) > 1: -            ret = False +if 1 <= k and k <= 9: +    print(k) +    exit() +d = deque([i for i in range(1, 10)]) +k -= 9 +while k > 0: +    num = d.popleft() +    if num % 10 != 0: +        new = 10 * num + (num % 10) - 1 +        d.append(new) +        k -= 1 +        if k == 0: -    return ret - - -lst = [i for i in range(10)] -dic = {} -dic[1] = lst.copy() -keta = 2 -while len(lst) < k + 1: -    new = [] -    for i in range(1, 10): -        tasu = i * (10 ** (keta - 1)) -        for j in sorted(dic.keys()): -            temp_lst = dic[j] -            bit = 0 -            for youso in temp_lst: -                num = tasu + youso -                if hantei(num): -                    new.append(num) -                    bit = 1 -                elif bit == 1: -                    break -    dic[keta] = new.copy() -    lst.extend(new) -    keta += 1 -print((lst[k])) +    new = 10 * num + (num % 10) +    d.append(new) +    k -= 1 +    if k == 0: +        break +    if num % 10 != 9: +        new = 10 * num + (num % 10) + 1 +        d.append(new) +        k -= 1 +        if k == 0: +            break +print(new)