def make_tree(G,keta,count):

    if keta==1:

        num =[]

        for i in range(1,10):

            count+=1

            if count ==k:

                print(i)

                exit()

            else:

                num.append(i)

        G.append(num)

        make_tree(G,2,count)

    else:

        

        num_list = G[keta-2]

        num_lis =[]

        for num in num_list:

            num_str = str(num)

            num_e = int(num_str[-1])

            if num_e == 0:

                count +=1

                if count == k :

                    print((int(num_str + "0")))

                    exit()

                num_lis.append(int((num_str)+"0"))

                count+=1

                if count == k :

                    print((int(num_str + "1")))

                    exit()

                num_lis.append(int((num_str)+"1"))

            elif num_e == 9:

                count +=1

                if count == k :

                    print((int(num_str + "8")))

                    exit()

                num_lis.append(int((num_str)+"8"))

                count+=1

                if count == k :

                    print((int(num_str + "9")))

                    exit()

                num_lis.append(int((num_str)+"9"))

            else:

                count +=1

                if count == k :

                    print((int(num_str + str(num_e-1))))

                    exit()

                num_lis.append(int(num_str + str(num_e-1)))

                count+=1

                if count == k :

                    print((int(num_str + str(num_e))))

                    exit()

                num_lis.append(int(num_str + str(num_e)))

                count+=1

                if count == k :

                    print((int(num_str + str(num_e+1))))

                    exit()

                num_lis.append(int(num_str + str(num_e+1)))

        G.append(num_lis)



        make_tree(G,keta+1,count)





k = int(eval(input()))

G=[]

make_tree(G,1,0)

def is_count_k(count,n):

    count +=1

    if count == k :

        print(n)

        exit()

    

    return count

def make_tree(G,keta,count):

    num_list = G[keta-2]

    new_list =[]

    for num in num_list:

        r = num%10

        if r != 0 :

            count = is_count_k(count,num*10 + (r-1))

            new_list.append(num*10 + r-1)

        count = is_count_k(count,num*10+r)

        new_list.append(num*10 + r)

        if r != 9:

            count = is_count_k(count,num*10+(r +1))

            new_list.append(num*10+(r +1))

    G.append(new_list)

    make_tree(G,keta+1,count)

k = int(eval(input()))

G=[]

if k < 10:

    print(k)

    exit()

G.append([1,2,3,4,5,6,7,8,9])

make_tree(G,2,9)

def make_tree(G, keta, count):
    if keta == 1:
        num = []
        for i in range(1, 10):
            count += 1
            if count == k:
                print(i)
                exit()
            else:
                num.append(i)
        G.append(num)
        make_tree(G, 2, count)
    else:
        num_list = G[keta - 2]
        num_lis = []
        for num in num_list:
            num_str = str(num)
            num_e = int(num_str[-1])
            if num_e == 0:
                count += 1
                if count == k:
                    print((int(num_str + "0")))
                    exit()
                num_lis.append(int((num_str) + "0"))
                count += 1
                if count == k:
                    print((int(num_str + "1")))
                    exit()
                num_lis.append(int((num_str) + "1"))
            elif num_e == 9:
                count += 1
                if count == k:
                    print((int(num_str + "8")))
                    exit()
                num_lis.append(int((num_str) + "8"))
                count += 1
                if count == k:
                    print((int(num_str + "9")))
                    exit()
                num_lis.append(int((num_str) + "9"))
            else:
                count += 1
                if count == k:
                    print((int(num_str + str(num_e - 1))))
                    exit()
                num_lis.append(int(num_str + str(num_e - 1)))
                count += 1
                if count == k:
                    print((int(num_str + str(num_e))))
                    exit()
                num_lis.append(int(num_str + str(num_e)))
                count += 1
                if count == k:
                    print((int(num_str + str(num_e + 1))))
                    exit()
                num_lis.append(int(num_str + str(num_e + 1)))
        G.append(num_lis)
        make_tree(G, keta + 1, count)


k = int(eval(input()))
G = []
make_tree(G, 1, 0)

def is_count_k(count, n):
    count += 1
    if count == k:
        print(n)
        exit()
    return count


def make_tree(G, keta, count):
    num_list = G[keta - 2]
    new_list = []
    for num in num_list:
        r = num % 10
        if r != 0:
            count = is_count_k(count, num * 10 + (r - 1))
            new_list.append(num * 10 + r - 1)
        count = is_count_k(count, num * 10 + r)
        new_list.append(num * 10 + r)
        if r != 9:
            count = is_count_k(count, num * 10 + (r + 1))
            new_list.append(num * 10 + (r + 1))
    G.append(new_list)
    make_tree(G, keta + 1, count)


k = int(eval(input()))
G = []
if k < 10:
    print(k)
    exit()
G.append([1, 2, 3, 4, 5, 6, 7, 8, 9])
make_tree(G, 2, 9)

+def is_count_k(count, n): +    count += 1 +    if count == k: +        print(n) +        exit() +    return count + + -    if keta == 1: -        num = [] -        for i in range(1, 10): -            count += 1 -            if count == k: -                print(i) -                exit() -            else: -                num.append(i) -        G.append(num) -        make_tree(G, 2, count) -    else: -        num_list = G[keta - 2] -        num_lis = [] -        for num in num_list: -            num_str = str(num) -            num_e = int(num_str[-1]) -            if num_e == 0: -                count += 1 -                if count == k: -                    print((int(num_str + "0"))) -                    exit() -                num_lis.append(int((num_str) + "0")) -                count += 1 -                if count == k: -                    print((int(num_str + "1"))) -                    exit() -                num_lis.append(int((num_str) + "1")) -            elif num_e == 9: -                count += 1 -                if count == k: -                    print((int(num_str + "8"))) -                    exit() -                num_lis.append(int((num_str) + "8")) -                count += 1 -                if count == k: -                    print((int(num_str + "9"))) -                    exit() -                num_lis.append(int((num_str) + "9")) -            else: -                count += 1 -                if count == k: -                    print((int(num_str + str(num_e - 1)))) -                    exit() -                num_lis.append(int(num_str + str(num_e - 1))) -                count += 1 -                if count == k: -                    print((int(num_str + str(num_e)))) -                    exit() -                num_lis.append(int(num_str + str(num_e))) -                count += 1 -                if count == k: -                    print((int(num_str + str(num_e + 1)))) -                    exit() -                num_lis.append(int(num_str + str(num_e + 1))) -        G.append(num_lis) -        make_tree(G, keta + 1, count) +    num_list = G[keta - 2] +    new_list = [] +    for num in num_list: +        r = num % 10 +        if r != 0: +            count = is_count_k(count, num * 10 + (r - 1)) +            new_list.append(num * 10 + r - 1) +        count = is_count_k(count, num * 10 + r) +        new_list.append(num * 10 + r) +        if r != 9: +            count = is_count_k(count, num * 10 + (r + 1)) +            new_list.append(num * 10 + (r + 1)) +    G.append(new_list) +    make_tree(G, keta + 1, count) -make_tree(G, 1, 0) +if k < 10: +    print(k) +    exit() +G.append([1, 2, 3, 4, 5, 6, 7, 8, 9]) +make_tree(G, 2, 9)