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]))
k = int(eval(input()))

# やっぱり一旦はglobalで書こ

total_ls = []

def dfs(A):

    if int(A) > 3234566667:

        return

    global total_ls

    total_ls.append(int(A))

    last = int(A[-1])

    if last == 0:

        nex = [1,0]

    elif last == 9:

        nex = [8,9]

    else:

        nex = [last-1,last,last+1]

    for n in nex:

        A += str(n)

        dfs(A)

        A = A[:-1]



for i in range(1,10):

    dfs(str(i))

total_ls.sort()

print((total_ls[k-1]))





    

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]))

k = int(eval(input()))
# やっぱり一旦はglobalで書こ
total_ls = []


def dfs(A):
    if int(A) > 3234566667:
        return
    global total_ls
    total_ls.append(int(A))
    last = int(A[-1])
    if last == 0:
        nex = [1, 0]
    elif last == 9:
        nex = [8, 9]
    else:
        nex = [last - 1, last, last + 1]
    for n in nex:
        A += str(n)
        dfs(A)
        A = A[:-1]


for i in range(1, 10):
    dfs(str(i))
total_ls.sort()
print((total_ls[k - 1]))

-lun_ls = [] +# やっぱり一旦はglobalで書こ +total_ls = [] -def change_to_num(ls): -    ls = list(map(str, ls)) -    strnum = "".join(ls) -    return int(strnum) +def dfs(A): +    if int(A) > 3234566667: +        return +    global total_ls +    total_ls.append(int(A)) +    last = int(A[-1]) +    if last == 0: +        nex = [1, 0] +    elif last == 9: +        nex = [8, 9] +    else: +        nex = [last - 1, last, last + 1] +    for n in nex: +        A += str(n) +        dfs(A) +        A = A[:-1] -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])) +for i in range(1, 10): +    dfs(str(i)) +total_ls.sort() +print((total_ls[k - 1]))