k = int(eval(input()))



def dfs(now, depth):

    STACK.append(str(now))

    if depth == limit:

        LUNLUN.append(int("".join(STACK)))

    else:

        for next in range(now - 1, now + 2):

            if next == -1 or next == 10:

                continue

            dfs(next, depth + 1)

    STACK.pop()



LUNLUN = []

STACK= []

for limit in range(10):

    for i in range(1, 10):

        dfs(i, 0)



print((LUNLUN[k - 1]))

k = int(eval(input()))



L = list(range(10))

i = 1

while len(L) <= k:

    Li = L[i]

    a = Li % 10

    for b in range(a - 1, a + 2):

        if b < 0 or b > 9:

            continue

        L.append(Li * 10 + b)

    i += 1



print((L[k]))

k = int(eval(input()))


def dfs(now, depth):
    STACK.append(str(now))
    if depth == limit:
        LUNLUN.append(int("".join(STACK)))
    else:
        for next in range(now - 1, now + 2):
            if next == -1 or next == 10:
                continue
            dfs(next, depth + 1)
    STACK.pop()


LUNLUN = []
STACK = []
for limit in range(10):
    for i in range(1, 10):
        dfs(i, 0)
print((LUNLUN[k - 1]))

k = int(eval(input()))
L = list(range(10))
i = 1
while len(L) <= k:
    Li = L[i]
    a = Li % 10
    for b in range(a - 1, a + 2):
        if b < 0 or b > 9:
            continue
        L.append(Li * 10 + b)
    i += 1
print((L[k]))

- - -def dfs(now, depth): -    STACK.append(str(now)) -    if depth == limit: -        LUNLUN.append(int("".join(STACK))) -    else: -        for next in range(now - 1, now + 2): -            if next == -1 or next == 10: -                continue -            dfs(next, depth + 1) -    STACK.pop() - - -LUNLUN = [] -STACK = [] -for limit in range(10): -    for i in range(1, 10): -        dfs(i, 0) -print((LUNLUN[k - 1])) +L = list(range(10)) +i = 1 +while len(L) <= k: +    Li = L[i] +    a = Li % 10 +    for b in range(a - 1, a + 2): +        if b < 0 or b > 9: +            continue +        L.append(Li * 10 + b) +    i += 1 +print((L[k]))