from collections import deque

k = int(eval(input()))





def generate_lunlun(x):

    d = int(x) % 10

    if d != 0:

        yield x+str(d-1)

    yield x+str(d)

    if d != 9:

        yield x+str(d+1)





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

for _ in range(k):

    x = d.popleft()

    for y in generate_lunlun(x):

        d.append(y)

print(x)

lunlun = []





def dfs(x):

    lunlun.append(x)

    if x > 3234566667:

        return 0

    d = x % 10

    if d != 0:

        dfs(10*x+d-1)

    dfs(10*x+d)

    if d != 9:

        dfs(10*x+d+1)





for i in range(1, 10):

    dfs(i)



lunlun.sort()

k = int(eval(input()))

print((lunlun[k-1]))
from collections import deque

k = int(eval(input()))


def generate_lunlun(x):
    d = int(x) % 10
    if d != 0:
        yield x + str(d - 1)
    yield x + str(d)
    if d != 9:
        yield x + str(d + 1)


d = deque([str(i) for i in range(1, 10)])
for _ in range(k):
    x = d.popleft()
    for y in generate_lunlun(x):
        d.append(y)
print(x)

lunlun = []


def dfs(x):
    lunlun.append(x)
    if x > 3234566667:
        return 0
    d = x % 10
    if d != 0:
        dfs(10 * x + d - 1)
    dfs(10 * x + d)
    if d != 9:
        dfs(10 * x + d + 1)


for i in range(1, 10):
    dfs(i)
lunlun.sort()
k = int(eval(input()))
print((lunlun[k - 1]))

-from collections import deque - -k = int(eval(input())) +lunlun = [] -def generate_lunlun(x): -    d = int(x) % 10 +def dfs(x): +    lunlun.append(x) +    if x > 3234566667: +        return 0 +    d = x % 10 -        yield x + str(d - 1) -    yield x + str(d) +        dfs(10 * x + d - 1) +    dfs(10 * x + d) -        yield x + str(d + 1) +        dfs(10 * x + d + 1) -d = deque([str(i) for i in range(1, 10)]) -for _ in range(k): -    x = d.popleft() -    for y in generate_lunlun(x): -        d.append(y) -print(x) +for i in range(1, 10): +    dfs(i) +lunlun.sort() +k = int(eval(input())) +print((lunlun[k - 1]))