def dfs(inParam, digits, lunlunCount, lunlun):

    if len(inParam) != digits:

        if int(inParam[len(inParam)-1]) == 0:

            nextNumList = [0, 1]

        elif int(inParam[len(inParam)-1]) == 9:

            nextNumList = [8, 9]

        else:

            nextNum = int(inParam[len(inParam)-1])

            nextNumList = [nextNum-1, nextNum, nextNum+1]

        

        for item in nextNumList:

            myTupp = dfs(inParam+str(item), digits, lunlunCount, lunlun)

            lunlunCount = myTupp[0]

            if myTupp[2] == 'e':

                return myTupp

        

        return myTupp

    

    else:

        lunlunCount += 1

        state = 'c'



        if lunlunCount == lunlun:

            state = 'e'

            print(inParam)



        return (lunlunCount, inParam, state)



K = int(eval(input()))



mylunlun = 0

mydigits = 1

while mylunlun != K:

    for indx in range(1, 10):

        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)

        # if mylunlun == K:

        #     break

    

    if mylunlun >= K:

        break



    mydigits += 1

K = int(eval(input()))



if K <= 9:

    print(K)

else:

    mylun = 9

    lunList = []



    for indx in range(1, 10):

        lunList.append(str(indx))



    while mylun < K:

        newLunList = []

        for lunItem in lunList:

            if lunItem[len(lunItem)-1] != "0":

                mylun += 1

                newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])-1 ))

                if mylun == K:

                    print((lunItem + str( int(lunItem[len(lunItem)-1])-1 )))

                    break

            

            mylun += 1

            newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1]) ))

            if mylun == K:

                print((lunItem + str( int(lunItem[len(lunItem)-1]) )))

                break



            if lunItem[len(lunItem)-1] != "9":

                mylun += 1

                newLunList.append(lunItem + str( int(lunItem[len(lunItem)-1])+1 ))

                if mylun == K:

                    print((lunItem + str( int(lunItem[len(lunItem)-1])+1 )))

                    break

        

        lunList = newLunList

def dfs(inParam, digits, lunlunCount, lunlun):
    if len(inParam) != digits:
        if int(inParam[len(inParam) - 1]) == 0:
            nextNumList = [0, 1]
        elif int(inParam[len(inParam) - 1]) == 9:
            nextNumList = [8, 9]
        else:
            nextNum = int(inParam[len(inParam) - 1])
            nextNumList = [nextNum - 1, nextNum, nextNum + 1]
        for item in nextNumList:
            myTupp = dfs(inParam + str(item), digits, lunlunCount, lunlun)
            lunlunCount = myTupp[0]
            if myTupp[2] == "e":
                return myTupp
        return myTupp
    else:
        lunlunCount += 1
        state = "c"
        if lunlunCount == lunlun:
            state = "e"
            print(inParam)
        return (lunlunCount, inParam, state)


K = int(eval(input()))
mylunlun = 0
mydigits = 1
while mylunlun != K:
    for indx in range(1, 10):
        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K)
        # if mylunlun == K:
        #     break
    if mylunlun >= K:
        break
    mydigits += 1

K = int(eval(input()))
if K <= 9:
    print(K)
else:
    mylun = 9
    lunList = []
    for indx in range(1, 10):
        lunList.append(str(indx))
    while mylun < K:
        newLunList = []
        for lunItem in lunList:
            if lunItem[len(lunItem) - 1] != "0":
                mylun += 1
                newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) - 1))
                if mylun == K:
                    print((lunItem + str(int(lunItem[len(lunItem) - 1]) - 1)))
                    break
            mylun += 1
            newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1])))
            if mylun == K:
                print((lunItem + str(int(lunItem[len(lunItem) - 1]))))
                break
            if lunItem[len(lunItem) - 1] != "9":
                mylun += 1
                newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) + 1))
                if mylun == K:
                    print((lunItem + str(int(lunItem[len(lunItem) - 1]) + 1)))
                    break
        lunList = newLunList

-def dfs(inParam, digits, lunlunCount, lunlun): -    if len(inParam) != digits: -        if int(inParam[len(inParam) - 1]) == 0: -            nextNumList = [0, 1] -        elif int(inParam[len(inParam) - 1]) == 9: -            nextNumList = [8, 9] -        else: -            nextNum = int(inParam[len(inParam) - 1]) -            nextNumList = [nextNum - 1, nextNum, nextNum + 1] -        for item in nextNumList: -            myTupp = dfs(inParam + str(item), digits, lunlunCount, lunlun) -            lunlunCount = myTupp[0] -            if myTupp[2] == "e": -                return myTupp -        return myTupp -    else: -        lunlunCount += 1 -        state = "c" -        if lunlunCount == lunlun: -            state = "e" -            print(inParam) -        return (lunlunCount, inParam, state) - - -mylunlun = 0 -mydigits = 1 -while mylunlun != K: +if K <= 9: +    print(K) +else: +    mylun = 9 +    lunList = [] -        mylunlun, lunlunNumber, _ = dfs(str(indx), mydigits, mylunlun, K) -        # if mylunlun == K: -        #     break -    if mylunlun >= K: -        break -    mydigits += 1 +        lunList.append(str(indx)) +    while mylun < K: +        newLunList = [] +        for lunItem in lunList: +            if lunItem[len(lunItem) - 1] != "0": +                mylun += 1 +                newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) - 1)) +                if mylun == K: +                    print((lunItem + str(int(lunItem[len(lunItem) - 1]) - 1))) +                    break +            mylun += 1 +            newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]))) +            if mylun == K: +                print((lunItem + str(int(lunItem[len(lunItem) - 1])))) +                break +            if lunItem[len(lunItem) - 1] != "9": +                mylun += 1 +                newLunList.append(lunItem + str(int(lunItem[len(lunItem) - 1]) + 1)) +                if mylun == K: +                    print((lunItem + str(int(lunItem[len(lunItem) - 1]) + 1))) +                    break +        lunList = newLunList