K = int(eval(input()))



def dfs(d, val, x):

    x.append(val)

    

    if d == 10:

        return

    

    for i in range(-1, 2):

        add = (val % 10) + i

        if 0 <= add <= 9:

            dfs(d + 1, val * 10 + add, x)



x = []

for i in range(1, 10):

    dfs(0, i, x)

print((sorted(x)[K - 1]))

from collections import deque



K = int(eval(input()))



q = deque(list(range(1, 10)))

ctr = 0

while ctr < K:

    val = q.popleft()

    ctr += 1

    for i in range(-1, 2):

        add = (val % 10) + i

        if 0 <= add <= 9:

            q.append(val * 10 + add)

            

print(val)

K = int(eval(input()))


def dfs(d, val, x):
    x.append(val)
    if d == 10:
        return
    for i in range(-1, 2):
        add = (val % 10) + i
        if 0 <= add <= 9:
            dfs(d + 1, val * 10 + add, x)


x = []
for i in range(1, 10):
    dfs(0, i, x)
print((sorted(x)[K - 1]))

from collections import deque

K = int(eval(input()))
q = deque(list(range(1, 10)))
ctr = 0
while ctr < K:
    val = q.popleft()
    ctr += 1
    for i in range(-1, 2):
        add = (val % 10) + i
        if 0 <= add <= 9:
            q.append(val * 10 + add)
print(val)

+from collections import deque + - - -def dfs(d, val, x): -    x.append(val) -    if d == 10: -        return +q = deque(list(range(1, 10))) +ctr = 0 +while ctr < K: +    val = q.popleft() +    ctr += 1 -            dfs(d + 1, val * 10 + add, x) - - -x = [] -for i in range(1, 10): -    dfs(0, i, x) -print((sorted(x)[K - 1])) +            q.append(val * 10 + add) +print(val)