# Original solution
# ABC161D
def f(k):
    if 1 <= k <= 9:
        print(k)
    else:
        nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
        cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
        for length, begin in enumerate(cum_npi):
            if k < begin:
                found = cum_npi[length - 1]
                break
        begin = 10 ** (length - 1)
        length, begin, found
        k -= found
        x = [[]] * (length + 1)
        x[1] = list(range(1, 10))
        x

        terminate = False
        i = 1
        while True:
            #print(f"a) i = {i}  x = {x}")
            if len(x[i]): # len(x[i])
                digit = x[i][0]
                if i < length: # i, length
                    i += 1
                    x[i] = nxt[digit].copy()
                    #print(f"x) digit = {digit}  nxt[digit] = {nxt[digit]}  i = {i}  x[i] = {x[i]}")
                    #print(f"b) i = {i}  x = {x}")
                    if i == length: # i, length
                        while len(x[i]): # i, x[i]
                            k -= 1
                            #print(f"c) i = {i}  x = {x}, k = {k}")
                            if k == 0:
                                x.pop(0)
                                #print("answer =", x)
                                ans = "".join([str(j.pop(0)) for j in x])
                                print(ans)
                                terminate = True
                                break
                            else:
                                x[i].pop(0)
                            #print(f"d) i = {i}  x = {x}")
                        else:
                            #print(f"e) i = {i}  x = {x}")
                            while len(x[i]) == 0:
                                i -= 1
                                x[i].pop(0)
                        if terminate:
                            break

f(int(eval(input())))


# Optimized solution
# ABC161D

def f(k):
    if 1 <= k <= 9:
        print(k)
    else:
        nxt = [[0,1], [0,1,2], [1,2,3], [2,3,4], [3,4,5], [4,5,6], [5,6,7], [6,7,8], [7,8,9], [8,9]]
        cum_npi = [0, 9, 35, 110, 327, 956, 2782, 8089, 23527, 68468, 199368]
        for length, begin in enumerate(cum_npi):
            if k < begin:
                found = cum_npi[length - 1]
                break
        begin = 10 ** (length - 1)
        # length, begin, found
        k -= found
        x = [[]] * (length + 1)
        x[1] = list(range(1, 10))
        # x

        terminate = False
        i = 1
        while True:
            #print(f"a) i = {i}  x = {x}")
            if len(x[i]): # len(x[i])
                digit = x[i][0]
                if i < length: # i, length
                    i += 1
                    x[i] = nxt[digit].copy()
                    #print(f"x) digit = {digit}  nxt[digit] = {nxt[digit]}  i = {i}  x[i] = {x[i]}")
                    #print(f"b) i = {i}  x = {x}")
                    if i == length: # i, length
                        while len(x[i]): # i, x[i]
                            k -= 1
                            #print(f"c) i = {i}  x = {x}, k = {k}")
                            if k == 0:
                                x.pop(0)
                                #print("answer =", x)
                                ans = "".join([str(j.pop(0)) for j in x])
                                print(ans)
                                terminate = True
                                break
                            else:
                                x[i].pop(0)
                            #print(f"d) i = {i}  x = {x}")
                        else:
                            #print(f"e) i = {i}  x = {x}")
                            while len(x[i]) == 0:
                                i -= 1
                                x[i].pop(0)
                        if terminate:
                            break

f(int(eval(input())))