from collections import deque

k = int(eval(input()))

d = deque([i for i in range(1,10)])



count = 0

while True:

    num = d.popleft()

    count += 1

    if count == k:

        break

    str_num = str(num)

    next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1]

    for digit in next_digit_ls:

        if 0<= digit <= 9:

            d.append(int(str_num + str(digit)))

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



lun_ls = []

def change_to_num(ls):

    ls = list(map(str, ls))

    strnum = ''.join(ls)

    return int(strnum)

def lun(num):

    '''

    渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出

    '''

    if num > 3234566667:

        return



    lun_ls.append(num)

    last = num % 10

    for nex in range(last-1, last+2):

        if 0<= nex < 10:

            new_str = str(num) + str(nex)

            new = int(new_str)

            lun(new)

            

for start in range(1,10):

    lun(start)

lun_ls.sort()

print((lun_ls[k-1]))
from collections import deque

k = int(eval(input()))
d = deque([i for i in range(1, 10)])
count = 0
while True:
    num = d.popleft()
    count += 1
    if count == k:
        break
    str_num = str(num)
    next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1]
    for digit in next_digit_ls:
        if 0 <= digit <= 9:
            d.append(int(str_num + str(digit)))
print(num)

k = int(eval(input()))
lun_ls = []


def change_to_num(ls):
    ls = list(map(str, ls))
    strnum = "".join(ls)
    return int(strnum)


def lun(num):
    """
    渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出
    """
    if num > 3234566667:
        return
    lun_ls.append(num)
    last = num % 10
    for nex in range(last - 1, last + 2):
        if 0 <= nex < 10:
            new_str = str(num) + str(nex)
            new = int(new_str)
            lun(new)


for start in range(1, 10):
    lun(start)
lun_ls.sort()
print((lun_ls[k - 1]))

-from collections import deque +k = int(eval(input())) +lun_ls = [] -k = int(eval(input())) -d = deque([i for i in range(1, 10)]) -count = 0 -while True: -    num = d.popleft() -    count += 1 -    if count == k: -        break -    str_num = str(num) -    next_digit_ls = [int(str_num[-1]) - 1, int(str_num[-1]), int(str_num[-1]) + 1] -    for digit in next_digit_ls: -        if 0 <= digit <= 9: -            d.append(int(str_num + str(digit))) -print(num) + +def change_to_num(ls): +    ls = list(map(str, ls)) +    strnum = "".join(ls) +    return int(strnum) + + +def lun(num): +    """ +    渡された数が上限行ってなければlun_lsに追加して、次の数で再帰呼出 +    """ +    if num > 3234566667: +        return +    lun_ls.append(num) +    last = num % 10 +    for nex in range(last - 1, last + 2): +        if 0 <= nex < 10: +            new_str = str(num) + str(nex) +            new = int(new_str) +            lun(new) + + +for start in range(1, 10): +    lun(start) +lun_ls.sort() +print((lun_ls[k - 1]))