def runrun(K,S):

    if K <= len(S):

        S.sort()

        ##print(S)

        print((S[K-1]))

        return 

    else:

        for i in range(len(S)):

            tmp = S[i]%10

            if tmp == 9:

                S.append(S[i]*10+8)

                S.append(S[i]*10+9)

            elif tmp == 0:

                S.append(S[i]*10+1)

                S.append(S[i]*10)

            else:

                S.append(S[i]*10+tmp-1)

                S.append(S[i]*10+tmp)

                S.append(S[i]*10+tmp+1)

        S = list(set(S))

        runrun(K,S)



if __name__ == "__main__":

    K = int(eval(input()))

    S = []

    for i in range(1,10):

        S.append(i)

    runrun(K,S)
def lunlun(K,S):

    if len(S) >= K:

        S.sort()

        print((S[K-1]))

        return



    for a in range(len(S)):

        i = S[a]

        rem = i%10

        n = 10*i + rem



        if rem == 9:

            S.append(n)

            S.append(n-1)

        elif rem == 0:

            S.append(n)

            S.append(n+1)

        else:

            S.append(n)

            S.append(n+1)

            S.append(n-1)

    lunlun(K,list(set(S)))





K = int(eval(input()))

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



lunlun(K,S)
def runrun(K, S):
    if K <= len(S):
        S.sort()
        ##print(S)
        print((S[K - 1]))
        return
    else:
        for i in range(len(S)):
            tmp = S[i] % 10
            if tmp == 9:
                S.append(S[i] * 10 + 8)
                S.append(S[i] * 10 + 9)
            elif tmp == 0:
                S.append(S[i] * 10 + 1)
                S.append(S[i] * 10)
            else:
                S.append(S[i] * 10 + tmp - 1)
                S.append(S[i] * 10 + tmp)
                S.append(S[i] * 10 + tmp + 1)
        S = list(set(S))
        runrun(K, S)


if __name__ == "__main__":
    K = int(eval(input()))
    S = []
    for i in range(1, 10):
        S.append(i)
    runrun(K, S)

def lunlun(K, S):
    if len(S) >= K:
        S.sort()
        print((S[K - 1]))
        return
    for a in range(len(S)):
        i = S[a]
        rem = i % 10
        n = 10 * i + rem
        if rem == 9:
            S.append(n)
            S.append(n - 1)
        elif rem == 0:
            S.append(n)
            S.append(n + 1)
        else:
            S.append(n)
            S.append(n + 1)
            S.append(n - 1)
    lunlun(K, list(set(S)))


K = int(eval(input()))
S = [i for i in range(1, 10)]
lunlun(K, S)

-def runrun(K, S): -    if K <= len(S): +def lunlun(K, S): +    if len(S) >= K: -        ##print(S) -    else: -        for i in range(len(S)): -            tmp = S[i] % 10 -            if tmp == 9: -                S.append(S[i] * 10 + 8) -                S.append(S[i] * 10 + 9) -            elif tmp == 0: -                S.append(S[i] * 10 + 1) -                S.append(S[i] * 10) -            else: -                S.append(S[i] * 10 + tmp - 1) -                S.append(S[i] * 10 + tmp) -                S.append(S[i] * 10 + tmp + 1) -        S = list(set(S)) -        runrun(K, S) +    for a in range(len(S)): +        i = S[a] +        rem = i % 10 +        n = 10 * i + rem +        if rem == 9: +            S.append(n) +            S.append(n - 1) +        elif rem == 0: +            S.append(n) +            S.append(n + 1) +        else: +            S.append(n) +            S.append(n + 1) +            S.append(n - 1) +    lunlun(K, list(set(S))) -if __name__ == "__main__": -    K = int(eval(input())) -    S = [] -    for i in range(1, 10): -        S.append(i) -    runrun(K, S) +K = int(eval(input())) +S = [i for i in range(1, 10)] +lunlun(K, S)