# Original solution
def main():
    K = int(eval(input())) 

    lunlun = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]

    start1 = ["1"]
    start2 = ["2"]
    start3 = ["3"]
    start4 = ["4"]
    start5 = ["5"]
    start6 = ["6"]
    start7 = ["7"]
    start8 = ["8"]
    start9 = ["9"]

    while len(lunlun) < 10 ** 5:
        next_starts = []
        for i in range(1, 10):
            news = []
            if i == 1:
                for n in start1:
                    if len(n) == 1:
                        new_n = n + "0"
                    else:
                        if abs(int(n[0])) > 1 or abs(int(n[1])) > 1:
                            break
                        new_n = n[0] + "0" + n[1:]
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start1:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start2:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 2:
                for n in start1:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start2:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start3:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 3:
                for n in start2:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start3:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start4:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 4:
                for n in start3:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start4:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start5:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 5:
                for n in start4:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start5:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start6:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 6:
                for n in start5:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start6:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start7:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 7:
                for n in start6:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start7:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start8:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 8:
                for n in start7:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start8:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start9:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)
            elif i == 9:
                for n in start8:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                for n in start9:
                    new_n = str(i) + n
                    lunlun.append(new_n)
                    news.append(new_n)
                next_starts.append(news)

        start1 = next_starts[0]
        start2 = next_starts[1]
        start3 = next_starts[2]
        start4 = next_starts[3]
        start5 = next_starts[4]
        start6 = next_starts[5]
        start7 = next_starts[6]
        start8 = next_starts[7]
        start9 = next_starts[8]

    print((lunlun[K-1]))

main()



# Optimized solution
from collections import deque

K = int(eval(input()))
queue = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
lunlun = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]

while len(queue) < 10 ** 5:
    n_str = queue.popleft()
    last_c = n_str[len(n_str) - 1]
    if last_c == "0":
        queue.append(n_str + "0")
        queue.append(n_str + "1")

        lunlun.append(n_str + "0")
        lunlun.append(n_str + "1")
    elif last_c == "1":
        queue.append(n_str + "0")
        queue.append(n_str + "1")
        queue.append(n_str + "2")

        lunlun.append(n_str + "0")
        lunlun.append(n_str + "1")
        lunlun.append(n_str + "2")
    elif last_c == "2":
        queue.append(n_str + "1")
        queue.append(n_str + "2")
        queue.append(n_str + "3")

        lunlun.append(n_str + "1")
        lunlun.append(n_str + "2")
        lunlun.append(n_str + "3")
    elif last_c == "3":
        queue.append(n_str + "2")
        queue.append(n_str + "3")
        queue.append(n_str + "4")

        lunlun.append(n_str + "2")
        lunlun.append(n_str + "3")
        lunlun.append(n_str + "4")
    elif last_c == "4":
        queue.append(n_str + "3")
        queue.append(n_str + "4")
        queue.append(n_str + "5")

        lunlun.append(n_str + "3")
        lunlun.append(n_str + "4")
        lunlun.append(n_str + "5")
    elif last_c == "5":
        queue.append(n_str + "4")
        queue.append(n_str + "5")
        queue.append(n_str + "6")

        lunlun.append(n_str + "4")
        lunlun.append(n_str + "5")
        lunlun.append(n_str + "6")
    elif last_c == "6":
        queue.append(n_str + "5")
        queue.append(n_str + "6")
        queue.append(n_str + "7")

        lunlun.append(n_str + "5")
        lunlun.append(n_str + "6")
        lunlun.append(n_str + "7")
    elif last_c == "7":
        queue.append(n_str + "6")
        queue.append(n_str + "7")
        queue.append(n_str + "8")

        lunlun.append(n_str + "6")
        lunlun.append(n_str + "7")
        lunlun.append(n_str + "8")
    elif last_c == "8":
        queue.append(n_str + "7")
        queue.append(n_str + "8")
        queue.append(n_str + "9")

        lunlun.append(n_str + "7")
        lunlun.append(n_str + "8")
        lunlun.append(n_str + "9")
    elif last_c == "9":
        queue.append(n_str + "8")
        queue.append(n_str + "9")

        lunlun.append(n_str + "8")
        lunlun.append(n_str + "9")

print((lunlun[K-1]))