from heapq import heapify, heappush, heappop



def next_num(n):

    if n == 0:

        return [0, 1]

    elif n == 9:

        return [8, 9]

    else:

        return [n-1, n, n+1]





K = int(eval(input()))



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

heapify(lunlun)



for _ in range(K-1):

    now = heappop(lunlun)

    for i in next_num(int(str(now)[-1])):

        heappush(lunlun, now*10+i)



print((lunlun[0]))

from heapq import heapify, heappush, heappop



K = int(eval(input()))



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

heapify(ll)



def next_num(X):

    n = int(str(X)[-1])

    if n == 0:

        return (0, 1)

    elif n == 9:

        return (8, 9)

    else:

        return (n-1, n, n+1)



for _ in range(K-1):

    lli = heappop(ll)

    next_nums = next_num(lli)

    for ni in next_nums:

        heappush(ll, lli*10+ni)



ans = ll[0]

print(ans)

from heapq import heapify, heappush, heappop


def next_num(n):
    if n == 0:
        return [0, 1]
    elif n == 9:
        return [8, 9]
    else:
        return [n - 1, n, n + 1]


K = int(eval(input()))
lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(lunlun)
for _ in range(K - 1):
    now = heappop(lunlun)
    for i in next_num(int(str(now)[-1])):
        heappush(lunlun, now * 10 + i)
print((lunlun[0]))

from heapq import heapify, heappush, heappop

K = int(eval(input()))
ll = [1, 2, 3, 4, 5, 6, 7, 8, 9]
heapify(ll)


def next_num(X):
    n = int(str(X)[-1])
    if n == 0:
        return (0, 1)
    elif n == 9:
        return (8, 9)
    else:
        return (n - 1, n, n + 1)


for _ in range(K - 1):
    lli = heappop(ll)
    next_nums = next_num(lli)
    for ni in next_nums:
        heappush(ll, lli * 10 + ni)
ans = ll[0]
print(ans)

- -def next_num(n): -    if n == 0: -        return [0, 1] -    elif n == 9: -        return [8, 9] -    else: -        return [n - 1, n, n + 1] +K = int(eval(input())) +ll = [1, 2, 3, 4, 5, 6, 7, 8, 9] +heapify(ll) -K = int(eval(input())) -lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9] -heapify(lunlun) +def next_num(X): +    n = int(str(X)[-1]) +    if n == 0: +        return (0, 1) +    elif n == 9: +        return (8, 9) +    else: +        return (n - 1, n, n + 1) + + -    now = heappop(lunlun) -    for i in next_num(int(str(now)[-1])): -        heappush(lunlun, now * 10 + i) -print((lunlun[0])) +    lli = heappop(ll) +    next_nums = next_num(lli) +    for ni in next_nums: +        heappush(ll, lli * 10 + ni) +ans = ll[0] +print(ans)