from collections import deque

K = int(eval(input()))



Queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(K):

    x = Queue[0]

    Queue.popleft()

    oneplace = x % 10



    #(1の位の数)-1を付け加えた数を入れる

    if oneplace == 0: #xの1の位が0

        pass

    else:   #xの1の位が0でない

        enqueue = x * 10 + (oneplace - 1)

        Queue.append(enqueue)

    

    #1の位の数を付け加えた数を入れる

    enqueue = x * 10 + oneplace

    Queue.append(enqueue)



    #(1の位の数)+1を付け加えた数を入れる

    if oneplace == 9:   #xの1の位の数が9

        pass

    else:

        enqueue = x * 10 + (oneplace + 1)

        Queue.append(enqueue)



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



B = [1, 2, 3, 4, 5, 6, 7, 8, 9] #Before list

while len(B) < k:

    k -= len(B)

    #次の桁に更新

    def update_next_digit(B:list)->list:

        N = []  #New list

        for i in range(len(B)):

            op = B[i] % 10  #one place   

            for j in [-1, 0, 1]:

                if 0 <= op+j and op+j <= 9:

                    N.append(B[i]*10+(op+j))

                else:

                    pass

        return N

    N = update_next_digit(B)

    B = N



ans = B[k-1]

print(ans)









from collections import deque

K = int(eval(input()))
Queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
    x = Queue[0]
    Queue.popleft()
    oneplace = x % 10
    # (1の位の数)-1を付け加えた数を入れる
    if oneplace == 0:  # xの1の位が0
        pass
    else:  # xの1の位が0でない
        enqueue = x * 10 + (oneplace - 1)
        Queue.append(enqueue)
    # 1の位の数を付け加えた数を入れる
    enqueue = x * 10 + oneplace
    Queue.append(enqueue)
    # (1の位の数)+1を付け加えた数を入れる
    if oneplace == 9:  # xの1の位の数が9
        pass
    else:
        enqueue = x * 10 + (oneplace + 1)
        Queue.append(enqueue)
print(x)

k = int(eval(input()))
B = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # Before list
while len(B) < k:
    k -= len(B)
    # 次の桁に更新
    def update_next_digit(B: list) -> list:
        N = []  # New list
        for i in range(len(B)):
            op = B[i] % 10  # one place
            for j in [-1, 0, 1]:
                if 0 <= op + j and op + j <= 9:
                    N.append(B[i] * 10 + (op + j))
                else:
                    pass
        return N

    N = update_next_digit(B)
    B = N
ans = B[k - 1]
print(ans)

-from collections import deque +k = int(eval(input())) +B = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # Before list +while len(B) < k: +    k -= len(B) +    # 次の桁に更新 +    def update_next_digit(B: list) -> list: +        N = []  # New list +        for i in range(len(B)): +            op = B[i] % 10  # one place +            for j in [-1, 0, 1]: +                if 0 <= op + j and op + j <= 9: +                    N.append(B[i] * 10 + (op + j)) +                else: +                    pass +        return N -K = int(eval(input())) -Queue = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) -for i in range(K): -    x = Queue[0] -    Queue.popleft() -    oneplace = x % 10 -    # (1の位の数)-1を付け加えた数を入れる -    if oneplace == 0:  # xの1の位が0 -        pass -    else:  # xの1の位が0でない -        enqueue = x * 10 + (oneplace - 1) -        Queue.append(enqueue) -    # 1の位の数を付け加えた数を入れる -    enqueue = x * 10 + oneplace -    Queue.append(enqueue) -    # (1の位の数)+1を付け加えた数を入れる -    if oneplace == 9:  # xの1の位の数が9 -        pass -    else: -        enqueue = x * 10 + (oneplace + 1) -        Queue.append(enqueue) -print(x) +    N = update_next_digit(B) +    B = N +ans = B[k - 1] +print(ans)