import sys

sys.setrecursionlimit(10**6)

from copy import deepcopy



def main():

    k = int(eval(input()))

    l = []

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



    def dfs(num, keta):

        #print(num,len(num),keta)



        if len(num) == keta:

            ll.append(int(num))

            #print(len(l))



        else:

            if num[-1] == '0':

                dfs(num + '0', keta)

                dfs(num + '1', keta)

            elif num[-1] == '9':

                dfs(num + '9', keta)

                dfs(num + '8', keta)

            else:

                dfs(num + str(int(num[-1]) + 1), keta)

                dfs(num + str(int(num[-1])), keta)

                dfs(num + str(int(num[-1]) - 1), keta)

    for i in range(2,10000):

        l = l + ll

        if len(l) > k:

            l.sort()

            print((l[k-1]))

            break

        else:

            tmp_ll = deepcopy(ll)

            ll = []

            for el in tmp_ll:

                dfs(str(el), i)







if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10**6)

read = sys.stdin.read

readlines = sys.stdin.readlines

from math import ceil, log

def main():

    k = int(eval(input()))

    k2 = int(log(ceil(k / 10), 3)) + 1

    def getlun(n, keta, last):

        lunluns.append(n)

        if keta > k2:

            pass

        else:

            l1 = n * 10 + last

            getlun(l1, keta + 1, last)

            if last > 0:

                l2 = n * 10 + last - 1

                getlun(l2, keta + 1, last - 1)

            if last < 9:

                l3 = n * 10 + last + 1

                getlun(l3, keta + 1, last + 1)

    lunluns = []

    for i1 in range(1, 10):

        getlun(i1, 0, i1)

    lunluns.sort()

    print((lunluns[k-1]))



if __name__ == '__main__':

    main()

import sys

sys.setrecursionlimit(10**6)
from copy import deepcopy


def main():
    k = int(eval(input()))
    l = []
    ll = [1, 2, 3, 4, 5, 6, 7, 8, 9]

    def dfs(num, keta):
        # print(num,len(num),keta)
        if len(num) == keta:
            ll.append(int(num))
            # print(len(l))
        else:
            if num[-1] == "0":
                dfs(num + "0", keta)
                dfs(num + "1", keta)
            elif num[-1] == "9":
                dfs(num + "9", keta)
                dfs(num + "8", keta)
            else:
                dfs(num + str(int(num[-1]) + 1), keta)
                dfs(num + str(int(num[-1])), keta)
                dfs(num + str(int(num[-1]) - 1), keta)

    for i in range(2, 10000):
        l = l + ll
        if len(l) > k:
            l.sort()
            print((l[k - 1]))
            break
        else:
            tmp_ll = deepcopy(ll)
            ll = []
            for el in tmp_ll:
                dfs(str(el), i)


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**6)
read = sys.stdin.read
readlines = sys.stdin.readlines
from math import ceil, log


def main():
    k = int(eval(input()))
    k2 = int(log(ceil(k / 10), 3)) + 1

    def getlun(n, keta, last):
        lunluns.append(n)
        if keta > k2:
            pass
        else:
            l1 = n * 10 + last
            getlun(l1, keta + 1, last)
            if last > 0:
                l2 = n * 10 + last - 1
                getlun(l2, keta + 1, last - 1)
            if last < 9:
                l3 = n * 10 + last + 1
                getlun(l3, keta + 1, last + 1)

    lunluns = []
    for i1 in range(1, 10):
        getlun(i1, 0, i1)
    lunluns.sort()
    print((lunluns[k - 1]))


if __name__ == "__main__":
    main()

-from copy import deepcopy +read = sys.stdin.read +readlines = sys.stdin.readlines +from math import ceil, log -    l = [] -    ll = [1, 2, 3, 4, 5, 6, 7, 8, 9] +    k2 = int(log(ceil(k / 10), 3)) + 1 -    def dfs(num, keta): -        # print(num,len(num),keta) -        if len(num) == keta: -            ll.append(int(num)) -            # print(len(l)) +    def getlun(n, keta, last): +        lunluns.append(n) +        if keta > k2: +            pass -            if num[-1] == "0": -                dfs(num + "0", keta) -                dfs(num + "1", keta) -            elif num[-1] == "9": -                dfs(num + "9", keta) -                dfs(num + "8", keta) -            else: -                dfs(num + str(int(num[-1]) + 1), keta) -                dfs(num + str(int(num[-1])), keta) -                dfs(num + str(int(num[-1]) - 1), keta) +            l1 = n * 10 + last +            getlun(l1, keta + 1, last) +            if last > 0: +                l2 = n * 10 + last - 1 +                getlun(l2, keta + 1, last - 1) +            if last < 9: +                l3 = n * 10 + last + 1 +                getlun(l3, keta + 1, last + 1) -    for i in range(2, 10000): -        l = l + ll -        if len(l) > k: -            l.sort() -            print((l[k - 1])) -            break -        else: -            tmp_ll = deepcopy(ll) -            ll = [] -            for el in tmp_ll: -                dfs(str(el), i) +    lunluns = [] +    for i1 in range(1, 10): +        getlun(i1, 0, i1) +    lunluns.sort() +    print((lunluns[k - 1]))