import heapq



k = int(eval(input()))



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

mae = 0



if k <= 9:

    print(k)

else:

    k -= 9

    q = []

    heapq.heapify(q)

    for i in range(1, 10):

        heapq.heappush(q, i)

    temp = 0

    while temp < 9:

        temp += 1

        num = heapq.heappop(q)

        if temp == 9:

            heapq.heappush(q, num*10 + num_list[(num%10)-1])

            heapq.heappush(q, num*10 + num_list[(num%10)])

        else:

            heapq.heappush(q, num*10 + num_list[(num%10)-1])

            heapq.heappush(q, num*10 + num_list[(num%10)])

            heapq.heappush(q, num*10 + num_list[(num%10)+1])

    while k > 0:

        k -= 1

        num = heapq.heappop(q)

        if num == mae:

            k += 1

            continue

        elif num%10 == 0:

            heapq.heappush(q, num*10 + num_list[(num%10)])

            heapq.heappush(q, num*10 + num_list[(num%10)+1])

        elif num%10 == 9:

            heapq.heappush(q, num*10 + num_list[(num%10)-1])

            heapq.heappush(q, num*10 + num_list[(num%10)])

        else:

            heapq.heappush(q, num*10 + num_list[(num%10)-1])

            heapq.heappush(q, num*10 + num_list[(num%10)])

            heapq.heappush(q, num*10 + num_list[(num%10)+1])

        mae = num

    print(num)

from collections import deque



k = int(eval(input()))

cnt = 9

q = deque([])

for i in range(1,10):

    q.append(i)

ans = 0



if k < 10:

    print(k)

else:

    while cnt != k:

        n = q.popleft()

        if n%10 == 0:

            tmp = n*10

            q.append(n*10)

            cnt += 1

            if cnt == k:

                print(tmp)

                break

            q.append(1+tmp)

            cnt += 1

            if cnt == k:

                print((tmp+1))

                break

        elif n%10 == 9:

            tmp = n*10

            q.append(tmp+8)

            cnt+=1

            if cnt == k:

                print((tmp+8))

                break

            q.append(tmp+9)

            cnt += 1

            if cnt == k:

                print((tmp+9))

                break

        else:

            tmp = n%10

            q.append(tmp-1+(n*10))

            cnt += 1

            if cnt ==k:

                print((tmp-1+(n*10)))

                break

            q.append(tmp+(n*10))

            cnt +=1

            if cnt == k:

                print((tmp+(n*10)))

                break

            q.append(tmp+1+(n*10))

            cnt += 1

            if cnt == k:

                print((tmp+1+(n*10)))

                break

import heapq

k = int(eval(input()))
num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
mae = 0
if k <= 9:
    print(k)
else:
    k -= 9
    q = []
    heapq.heapify(q)
    for i in range(1, 10):
        heapq.heappush(q, i)
    temp = 0
    while temp < 9:
        temp += 1
        num = heapq.heappop(q)
        if temp == 9:
            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1])
            heapq.heappush(q, num * 10 + num_list[(num % 10)])
        else:
            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1])
            heapq.heappush(q, num * 10 + num_list[(num % 10)])
            heapq.heappush(q, num * 10 + num_list[(num % 10) + 1])
    while k > 0:
        k -= 1
        num = heapq.heappop(q)
        if num == mae:
            k += 1
            continue
        elif num % 10 == 0:
            heapq.heappush(q, num * 10 + num_list[(num % 10)])
            heapq.heappush(q, num * 10 + num_list[(num % 10) + 1])
        elif num % 10 == 9:
            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1])
            heapq.heappush(q, num * 10 + num_list[(num % 10)])
        else:
            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1])
            heapq.heappush(q, num * 10 + num_list[(num % 10)])
            heapq.heappush(q, num * 10 + num_list[(num % 10) + 1])
        mae = num
    print(num)

from collections import deque

k = int(eval(input()))
cnt = 9
q = deque([])
for i in range(1, 10):
    q.append(i)
ans = 0
if k < 10:
    print(k)
else:
    while cnt != k:
        n = q.popleft()
        if n % 10 == 0:
            tmp = n * 10
            q.append(n * 10)
            cnt += 1
            if cnt == k:
                print(tmp)
                break
            q.append(1 + tmp)
            cnt += 1
            if cnt == k:
                print((tmp + 1))
                break
        elif n % 10 == 9:
            tmp = n * 10
            q.append(tmp + 8)
            cnt += 1
            if cnt == k:
                print((tmp + 8))
                break
            q.append(tmp + 9)
            cnt += 1
            if cnt == k:
                print((tmp + 9))
                break
        else:
            tmp = n % 10
            q.append(tmp - 1 + (n * 10))
            cnt += 1
            if cnt == k:
                print((tmp - 1 + (n * 10)))
                break
            q.append(tmp + (n * 10))
            cnt += 1
            if cnt == k:
                print((tmp + (n * 10)))
                break
            q.append(tmp + 1 + (n * 10))
            cnt += 1
            if cnt == k:
                print((tmp + 1 + (n * 10)))
                break

-import heapq +from collections import deque -num_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] -mae = 0 -if k <= 9: +cnt = 9 +q = deque([]) +for i in range(1, 10): +    q.append(i) +ans = 0 +if k < 10: -    k -= 9 -    q = [] -    heapq.heapify(q) -    for i in range(1, 10): -        heapq.heappush(q, i) -    temp = 0 -    while temp < 9: -        temp += 1 -        num = heapq.heappop(q) -        if temp == 9: -            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1]) -            heapq.heappush(q, num * 10 + num_list[(num % 10)]) +    while cnt != k: +        n = q.popleft() +        if n % 10 == 0: +            tmp = n * 10 +            q.append(n * 10) +            cnt += 1 +            if cnt == k: +                print(tmp) +                break +            q.append(1 + tmp) +            cnt += 1 +            if cnt == k: +                print((tmp + 1)) +                break +        elif n % 10 == 9: +            tmp = n * 10 +            q.append(tmp + 8) +            cnt += 1 +            if cnt == k: +                print((tmp + 8)) +                break +            q.append(tmp + 9) +            cnt += 1 +            if cnt == k: +                print((tmp + 9)) +                break -            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1]) -            heapq.heappush(q, num * 10 + num_list[(num % 10)]) -            heapq.heappush(q, num * 10 + num_list[(num % 10) + 1]) -    while k > 0: -        k -= 1 -        num = heapq.heappop(q) -        if num == mae: -            k += 1 -            continue -        elif num % 10 == 0: -            heapq.heappush(q, num * 10 + num_list[(num % 10)]) -            heapq.heappush(q, num * 10 + num_list[(num % 10) + 1]) -        elif num % 10 == 9: -            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1]) -            heapq.heappush(q, num * 10 + num_list[(num % 10)]) -        else: -            heapq.heappush(q, num * 10 + num_list[(num % 10) - 1]) -            heapq.heappush(q, num * 10 + num_list[(num % 10)]) -            heapq.heappush(q, num * 10 + num_list[(num % 10) + 1]) -        mae = num -    print(num) +            tmp = n % 10 +            q.append(tmp - 1 + (n * 10)) +            cnt += 1 +            if cnt == k: +                print((tmp - 1 + (n * 10))) +                break +            q.append(tmp + (n * 10)) +            cnt += 1 +            if cnt == k: +                print((tmp + (n * 10))) +                break +            q.append(tmp + 1 + (n * 10)) +            cnt += 1 +            if cnt == k: +                print((tmp + 1 + (n * 10))) +                break