def solve():

    K = int(eval(input()))

    cnt = 0

    n_digit = 1

    numbers = []

    while cnt < K:

        numbers = []

        dfs("", numbers, n_digit)

        cnt += len(numbers)

        n_digit += 1

    

    print((numbers[-(cnt - K + 1)]))

    

def dfs(now, numbers, n_digit):

    if len(now) == n_digit:

        numbers.append(now)

        return

    

    if now == "":

        for i in range(1,10):

            dfs(now+str(i), numbers, n_digit)

    else:

        last_num = int(now[-1])

        if last_num - 1 >= 0:

            dfs(now+str(last_num-1), numbers, n_digit)



        dfs(now+str(last_num), numbers, n_digit)



        if last_num + 1 <= 9:

            dfs(now+str(last_num+1), numbers, n_digit)



if __name__ == '__main__':

    solve()
from collections import deque

def solve():

    K = int(eval(input()))

    q = deque(list(range(1,10)))

    cnt = 0



    tmp = 0

    while cnt < K:

        tmp = q.popleft()

        cnt += 1



        ones_place = tmp % 10

        if ones_place != 0:

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

        q.append(tmp*10+ones_place)

        if ones_place != 9:

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

    

    print(tmp)

        

if __name__ == '__main__':

    solve()
def solve():
    K = int(eval(input()))
    cnt = 0
    n_digit = 1
    numbers = []
    while cnt < K:
        numbers = []
        dfs("", numbers, n_digit)
        cnt += len(numbers)
        n_digit += 1
    print((numbers[-(cnt - K + 1)]))


def dfs(now, numbers, n_digit):
    if len(now) == n_digit:
        numbers.append(now)
        return
    if now == "":
        for i in range(1, 10):
            dfs(now + str(i), numbers, n_digit)
    else:
        last_num = int(now[-1])
        if last_num - 1 >= 0:
            dfs(now + str(last_num - 1), numbers, n_digit)
        dfs(now + str(last_num), numbers, n_digit)
        if last_num + 1 <= 9:
            dfs(now + str(last_num + 1), numbers, n_digit)


if __name__ == "__main__":
    solve()

from collections import deque


def solve():
    K = int(eval(input()))
    q = deque(list(range(1, 10)))
    cnt = 0
    tmp = 0
    while cnt < K:
        tmp = q.popleft()
        cnt += 1
        ones_place = tmp % 10
        if ones_place != 0:
            q.append(tmp * 10 + ones_place - 1)
        q.append(tmp * 10 + ones_place)
        if ones_place != 9:
            q.append(tmp * 10 + ones_place + 1)
    print(tmp)


if __name__ == "__main__":
    solve()

+from collections import deque + + +    q = deque(list(range(1, 10))) -    n_digit = 1 -    numbers = [] +    tmp = 0 -        numbers = [] -        dfs("", numbers, n_digit) -        cnt += len(numbers) -        n_digit += 1 -    print((numbers[-(cnt - K + 1)])) - - -def dfs(now, numbers, n_digit): -    if len(now) == n_digit: -        numbers.append(now) -        return -    if now == "": -        for i in range(1, 10): -            dfs(now + str(i), numbers, n_digit) -    else: -        last_num = int(now[-1]) -        if last_num - 1 >= 0: -            dfs(now + str(last_num - 1), numbers, n_digit) -        dfs(now + str(last_num), numbers, n_digit) -        if last_num + 1 <= 9: -            dfs(now + str(last_num + 1), numbers, n_digit) +        tmp = q.popleft() +        cnt += 1 +        ones_place = tmp % 10 +        if ones_place != 0: +            q.append(tmp * 10 + ones_place - 1) +        q.append(tmp * 10 + ones_place) +        if ones_place != 9: +            q.append(tmp * 10 + ones_place + 1) +    print(tmp)