K = int(eval(input()))

import copy



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

while K >= len(present):

    K -= len(present)

    next = []

    for i in range(len(present)):

        tmp = present[i]

        r = tmp % 10

        if r != 0:

            next.append(tmp * 10 + r -1)

        next.append(tmp * 10 + r)

        if r != 9:

            next.append(tmp * 10 + r +1)

    present = next



print((present[K-1]))
K = int(eval(input()))



old = []

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



while K > len(old):

    new = []

    K -= len(old)

    for i in range(len(old)):

        tmp = old[i]

        l = tmp % 10

        if l != 0:

            new.append(tmp*10+l-1)

        new.append(tmp*10+l)

        if l != 9:

            new.append(tmp*10+l+1)

    old = new[:]







print((old[K-1]))
K = int(eval(input()))
import copy

present = [1, 2, 3, 4, 5, 6, 7, 8, 9]
while K >= len(present):
    K -= len(present)
    next = []
    for i in range(len(present)):
        tmp = present[i]
        r = tmp % 10
        if r != 0:
            next.append(tmp * 10 + r - 1)
        next.append(tmp * 10 + r)
        if r != 9:
            next.append(tmp * 10 + r + 1)
    present = next
print((present[K - 1]))

K = int(eval(input()))
old = []
old = [i for i in range(1, 10)]
while K > len(old):
    new = []
    K -= len(old)
    for i in range(len(old)):
        tmp = old[i]
        l = tmp % 10
        if l != 0:
            new.append(tmp * 10 + l - 1)
        new.append(tmp * 10 + l)
        if l != 9:
            new.append(tmp * 10 + l + 1)
    old = new[:]
print((old[K - 1]))

-import copy - -present = [1, 2, 3, 4, 5, 6, 7, 8, 9] -while K >= len(present): -    K -= len(present) -    next = [] -    for i in range(len(present)): -        tmp = present[i] -        r = tmp % 10 -        if r != 0: -            next.append(tmp * 10 + r - 1) -        next.append(tmp * 10 + r) -        if r != 9: -            next.append(tmp * 10 + r + 1) -    present = next -print((present[K - 1])) +old = [] +old = [i for i in range(1, 10)] +while K > len(old): +    new = [] +    K -= len(old) +    for i in range(len(old)): +        tmp = old[i] +        l = tmp % 10 +        if l != 0: +            new.append(tmp * 10 + l - 1) +        new.append(tmp * 10 + l) +        if l != 9: +            new.append(tmp * 10 + l + 1) +    old = new[:] +print((old[K - 1]))