k = int(eval(input()))



numset = {i for i in range(1,10)}

flag = False

count = len(numset)

if count >= k:

    flag = True

arr = [numset]

index = 0



while not flag:

    beforeset = arr[index]

    tmpset = set()

    for i in beforeset:

        tail = str(i)[-1]

        if tail == "0":

            tmpset.add(int(str(i)+str(0)))

            tmpset.add(int(str(i)+str(1)))

        elif tail == "9":

            tmpset.add(int(str(i)+str(8)))

            tmpset.add(int(str(i)+str(9)))

        else:

            tmpset.add(int(str(i)+str(int(tail))))

            tmpset.add(int(str(i)+str(int(tail)+1)))

            tmpset.add(int(str(i)+str(int(tail)-1)))

    count += len(tmpset)

    if count >= k:

        flag = True

    arr.append(tmpset)

    index += 1

    

totalarr = []

for tmpset in arr:

    totalarr += list(tmpset)

    

totalarr.sort()

print((totalarr[k-1]))
k = int(eval(input()))



from collections import deque

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

count = 0



while count < k:

    tmp = queue.popleft()

    tail = tmp%10

    if tail != 0:

        queue.append(tmp*10+tail-1)

    queue.append(tmp*10+tail)

    if tail != 9:

        queue.append(tmp*10+tail+1)

    count += 1

    

print(tmp)

k = int(eval(input()))
numset = {i for i in range(1, 10)}
flag = False
count = len(numset)
if count >= k:
    flag = True
arr = [numset]
index = 0
while not flag:
    beforeset = arr[index]
    tmpset = set()
    for i in beforeset:
        tail = str(i)[-1]
        if tail == "0":
            tmpset.add(int(str(i) + str(0)))
            tmpset.add(int(str(i) + str(1)))
        elif tail == "9":
            tmpset.add(int(str(i) + str(8)))
            tmpset.add(int(str(i) + str(9)))
        else:
            tmpset.add(int(str(i) + str(int(tail))))
            tmpset.add(int(str(i) + str(int(tail) + 1)))
            tmpset.add(int(str(i) + str(int(tail) - 1)))
    count += len(tmpset)
    if count >= k:
        flag = True
    arr.append(tmpset)
    index += 1
totalarr = []
for tmpset in arr:
    totalarr += list(tmpset)
totalarr.sort()
print((totalarr[k - 1]))

k = int(eval(input()))
from collections import deque

queue = deque(list(range(1, 10)))
count = 0
while count < k:
    tmp = queue.popleft()
    tail = tmp % 10
    if tail != 0:
        queue.append(tmp * 10 + tail - 1)
    queue.append(tmp * 10 + tail)
    if tail != 9:
        queue.append(tmp * 10 + tail + 1)
    count += 1
print(tmp)

-numset = {i for i in range(1, 10)} -flag = False -count = len(numset) -if count >= k: -    flag = True -arr = [numset] -index = 0 -while not flag: -    beforeset = arr[index] -    tmpset = set() -    for i in beforeset: -        tail = str(i)[-1] -        if tail == "0": -            tmpset.add(int(str(i) + str(0))) -            tmpset.add(int(str(i) + str(1))) -        elif tail == "9": -            tmpset.add(int(str(i) + str(8))) -            tmpset.add(int(str(i) + str(9))) -        else: -            tmpset.add(int(str(i) + str(int(tail)))) -            tmpset.add(int(str(i) + str(int(tail) + 1))) -            tmpset.add(int(str(i) + str(int(tail) - 1))) -    count += len(tmpset) -    if count >= k: -        flag = True -    arr.append(tmpset) -    index += 1 -totalarr = [] -for tmpset in arr: -    totalarr += list(tmpset) -totalarr.sort() -print((totalarr[k - 1])) +from collections import deque + +queue = deque(list(range(1, 10))) +count = 0 +while count < k: +    tmp = queue.popleft() +    tail = tmp % 10 +    if tail != 0: +        queue.append(tmp * 10 + tail - 1) +    queue.append(tmp * 10 + tail) +    if tail != 9: +        queue.append(tmp * 10 + tail + 1) +    count += 1 +print(tmp)