import sys

sys.setrecursionlimit(10**9)



def main():

    K = int(eval(input()))

    if 0<=K<=10:

        print(K)

        exit()



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

    m = 0



    while len(lunlun) < K:

        x = lunlun[m]

        btm = x % 10



        if btm - 1 >= 0:

            lunlun.append(10*x+btm-1)



        lunlun.append(10*x+btm)



        if btm + 1 < 10:

            lunlun.append(10*x+btm+1)



        m += 1



    print((lunlun[::-1][len(lunlun)-K]))



if __name__ == "__main__":

  main()

import sys

sys.setrecursionlimit(10**9)



def mi(): return list(map(int,input().split()))

def ii(): return int(eval(input()))

def isp(): return input().split()

def deb(text): print(("-------\n{}\n-------".format(text)))



INF=10**20

def main():

    K=ii()

    L=list(range(10))



    if K <= 9:

        print(K)

        exit()

    

    # print(L)

    head_i = 1

    while len(L) < K+10:

        assert head_i < len(L)

        head = L[head_i]

        head_tail = head % 10

        for x in [head_tail-1,head_tail,head_tail+1]:

            if x < 0 or x >= 10: continue

            

            # print(head_i,head,head_tail)

            # assert not head * 10 + x in L

            L.append(head * 10 + x)

        

        head_i += 1



    # print(L)

    print((L[K]))



    





if __name__ == "__main__":

    main()
import sys

sys.setrecursionlimit(10**9)


def main():
    K = int(eval(input()))
    if 0 <= K <= 10:
        print(K)
        exit()
    lunlun = [i for i in range(1, 10)]
    m = 0
    while len(lunlun) < K:
        x = lunlun[m]
        btm = x % 10
        if btm - 1 >= 0:
            lunlun.append(10 * x + btm - 1)
        lunlun.append(10 * x + btm)
        if btm + 1 < 10:
            lunlun.append(10 * x + btm + 1)
        m += 1
    print((lunlun[::-1][len(lunlun) - K]))


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**9)


def mi():
    return list(map(int, input().split()))


def ii():
    return int(eval(input()))


def isp():
    return input().split()


def deb(text):
    print(("-------\n{}\n-------".format(text)))


INF = 10**20


def main():
    K = ii()
    L = list(range(10))
    if K <= 9:
        print(K)
        exit()
    # print(L)
    head_i = 1
    while len(L) < K + 10:
        assert head_i < len(L)
        head = L[head_i]
        head_tail = head % 10
        for x in [head_tail - 1, head_tail, head_tail + 1]:
            if x < 0 or x >= 10:
                continue
            # print(head_i,head,head_tail)
            # assert not head * 10 + x in L
            L.append(head * 10 + x)
        head_i += 1
    # print(L)
    print((L[K]))


if __name__ == "__main__":
    main()

+def mi(): +    return list(map(int, input().split())) + + +def ii(): +    return int(eval(input())) + + +def isp(): +    return input().split() + + +def deb(text): + + +INF = 10**20 + + -    K = int(eval(input())) -    if 0 <= K <= 10: +    K = ii() +    L = list(range(10)) +    if K <= 9: -    lunlun = [i for i in range(1, 10)] -    m = 0 -    while len(lunlun) < K: -        x = lunlun[m] -        btm = x % 10 -        if btm - 1 >= 0: -            lunlun.append(10 * x + btm - 1) -        lunlun.append(10 * x + btm) -        if btm + 1 < 10: -            lunlun.append(10 * x + btm + 1) -        m += 1 -    print((lunlun[::-1][len(lunlun) - K])) +    # print(L) +    head_i = 1 +    while len(L) < K + 10: +        assert head_i < len(L) +        head = L[head_i] +        head_tail = head % 10 +        for x in [head_tail - 1, head_tail, head_tail + 1]: +            if x < 0 or x >= 10: +                continue +            # print(head_i,head,head_tail) +            # assert not head * 10 + x in L +            L.append(head * 10 + x) +        head_i += 1 +    # print(L) +    print((L[K]))