from collections import deque



k = int(eval(input()))



if 1 <= k and k <= 9:

    print(k)

    exit()



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

k -= 9

while k > 0:

    num = d.popleft()

    if num % 10 != 0:

        new = 10*num + (num%10) - 1

        d.append(new)

        k -= 1

        if k == 0: break

    new = 10*num + (num%10)

    d.append(new)

    k -= 1

    if k == 0: break

    if num % 10 != 9:

        new = 10*num + (num%10) + 1

        d.append(new)

        k -= 1

        if k == 0: break



print(new)
k = int(eval(input()))



if k <= 9:

    print(k)

k -= 9



lst = list(range(1, 10))

while k > 0:

    new = []

    for num in lst:

        amari = num % 10

        if amari == 0:

            new.append(num*10)

            new.append(num*10+1)

        elif amari == 9:

            new.append(num*10+8)

            new.append(num*10+9)

        else:

            new.append(num*10+(amari-1))

            new.append(num*10+amari)

            new.append(num*10+(amari+1))

    if len(new) >= k:

        print((new[k-1]))

        exit()

    else:

        k -= len(new)

        lst = new
from collections import deque

k = int(eval(input()))
if 1 <= k and k <= 9:
    print(k)
    exit()
d = deque([i for i in range(1, 10)])
k -= 9
while k > 0:
    num = d.popleft()
    if num % 10 != 0:
        new = 10 * num + (num % 10) - 1
        d.append(new)
        k -= 1
        if k == 0:
            break
    new = 10 * num + (num % 10)
    d.append(new)
    k -= 1
    if k == 0:
        break
    if num % 10 != 9:
        new = 10 * num + (num % 10) + 1
        d.append(new)
        k -= 1
        if k == 0:
            break
print(new)

k = int(eval(input()))
if k <= 9:
    print(k)
k -= 9
lst = list(range(1, 10))
while k > 0:
    new = []
    for num in lst:
        amari = num % 10
        if amari == 0:
            new.append(num * 10)
            new.append(num * 10 + 1)
        elif amari == 9:
            new.append(num * 10 + 8)
            new.append(num * 10 + 9)
        else:
            new.append(num * 10 + (amari - 1))
            new.append(num * 10 + amari)
            new.append(num * 10 + (amari + 1))
    if len(new) >= k:
        print((new[k - 1]))
        exit()
    else:
        k -= len(new)
        lst = new

-from collections import deque - -if 1 <= k and k <= 9: +if k <= 9: -    exit() -d = deque([i for i in range(1, 10)]) +lst = list(range(1, 10)) -    num = d.popleft() -    if num % 10 != 0: -        new = 10 * num + (num % 10) - 1 -        d.append(new) -        k -= 1 -        if k == 0: -            break -    new = 10 * num + (num % 10) -    d.append(new) -    k -= 1 -    if k == 0: -        break -    if num % 10 != 9: -        new = 10 * num + (num % 10) + 1 -        d.append(new) -        k -= 1 -        if k == 0: -            break -print(new) +    new = [] +    for num in lst: +        amari = num % 10 +        if amari == 0: +            new.append(num * 10) +            new.append(num * 10 + 1) +        elif amari == 9: +            new.append(num * 10 + 8) +            new.append(num * 10 + 9) +        else: +            new.append(num * 10 + (amari - 1)) +            new.append(num * 10 + amari) +            new.append(num * 10 + (amari + 1)) +    if len(new) >= k: +        print((new[k - 1])) +        exit() +    else: +        k -= len(new) +        lst = new