K = int(eval(input()))

a = set([1,2,3,4,5,6,7,8,9])

prev = set([1,2,3,4,5,6,7,8,9])



while len(a) < K:

    temp = set()

    for now in prev:

        c = now%10

        if c == 0:

            temp.add(now*10)

            temp.add(now*10+1)

        elif c == 9:

            temp.add(now*10+9)

            temp.add(now*10+8)

        else:

            temp.add(now*10+c-1)

            temp.add(now*10+c)

            temp.add(now*10+c+1)

    prev = temp

    a = a|temp

print((sorted(list(a))[K-1]))

K = int(eval(input()))

S = set([1,2,3,4,5,6,7,8,9])

prev = set([1,2,3,4,5,6,7,8,9])



while len(S) < K:

    temp = set([])

    for e in prev:

        if e%10 == 0:

            temp.add(e*10)

            temp.add(e*10+1)

        elif e%10 == 9:

            temp.add(e*10+8)

            temp.add(e*10+9)

        else:

            temp.add(e*10+e%10-1)

            temp.add(e*10+e%10)

            temp.add(e*10+e%10+1)

    prev = temp

    S = S|temp

print((sorted(list(S))[K-1]))

K = int(eval(input()))
a = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
prev = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
while len(a) < K:
    temp = set()
    for now in prev:
        c = now % 10
        if c == 0:
            temp.add(now * 10)
            temp.add(now * 10 + 1)
        elif c == 9:
            temp.add(now * 10 + 9)
            temp.add(now * 10 + 8)
        else:
            temp.add(now * 10 + c - 1)
            temp.add(now * 10 + c)
            temp.add(now * 10 + c + 1)
    prev = temp
    a = a | temp
print((sorted(list(a))[K - 1]))

K = int(eval(input()))
S = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
prev = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
while len(S) < K:
    temp = set([])
    for e in prev:
        if e % 10 == 0:
            temp.add(e * 10)
            temp.add(e * 10 + 1)
        elif e % 10 == 9:
            temp.add(e * 10 + 8)
            temp.add(e * 10 + 9)
        else:
            temp.add(e * 10 + e % 10 - 1)
            temp.add(e * 10 + e % 10)
            temp.add(e * 10 + e % 10 + 1)
    prev = temp
    S = S | temp
print((sorted(list(S))[K - 1]))

-a = set([1, 2, 3, 4, 5, 6, 7, 8, 9]) +S = set([1, 2, 3, 4, 5, 6, 7, 8, 9]) -while len(a) < K: -    temp = set() -    for now in prev: -        c = now % 10 -        if c == 0: -            temp.add(now * 10) -            temp.add(now * 10 + 1) -        elif c == 9: -            temp.add(now * 10 + 9) -            temp.add(now * 10 + 8) +while len(S) < K: +    temp = set([]) +    for e in prev: +        if e % 10 == 0: +            temp.add(e * 10) +            temp.add(e * 10 + 1) +        elif e % 10 == 9: +            temp.add(e * 10 + 8) +            temp.add(e * 10 + 9) -            temp.add(now * 10 + c - 1) -            temp.add(now * 10 + c) -            temp.add(now * 10 + c + 1) +            temp.add(e * 10 + e % 10 - 1) +            temp.add(e * 10 + e % 10) +            temp.add(e * 10 + e % 10 + 1) -    a = a | temp -print((sorted(list(a))[K - 1])) +    S = S | temp +print((sorted(list(S))[K - 1]))