import sys



sys.setrecursionlimit(10**6)



def dfs(n, before):

    global cnt, K, ans, flag

    ints = int(before[-1])

    int1s = ints - 1; ints1 = ints + 1



    if int1s >= 0:

        after1s = before + str(int1s)

        if n == 1: 

            cnt += 1

        if cnt == K and flag == 0:

            ans = after1s; flag = 1

            return

        if n >= 2:

            dfs(n-1, after1s)

    

    afters = before + str(ints)

    if n == 1:

        cnt += 1

    if cnt == K and flag == 0:

        ans = afters; flag = 1

        return

    if n >= 2:

        dfs(n-1, afters)



    if ints1 <= 9:

        afters1 = before + str(ints1)

        if n == 1:

            cnt += 1

        if cnt == K and flag == 0:

            ans = afters1; flag = 1

        if n >= 2:

            dfs(n-1, afters1)





def main():

    global cnt, K, ans, flag

    K = int(eval(input()))

    if K <= 9:

        print(K)

        return

    cnt = 9

    flag = 0

    for n in range(1, 13):

        for s in range(1, 10):

            dfs(n, str(s))

            if flag == 1:

                break

        if flag == 1:

            break

    print(ans)



if __name__ == "__main__":

    main()

import sys



sys.setrecursionlimit(10**6)



def dfs(base, n):

    global K, cnt, ans, flag

    if flag:

        return

    if n == 0:

        cnt += 1

        if cnt == K:

            ans = int(base)

            flag = True

            return

    else:

        last = int(base[-1])

        for l in range(max(0, last-1), min(10, last+2)):

            nextbase = base + str(l)

            dfs(nextbase, n-1)





def main():

    global K, ans, cnt, flag

    K = int(eval(input()))

    if K < 10:

        print(K)

        return

    leftK = int(str(K)[0])

    cnt = 9; ans = 0

    flag = False

    for keta in range(1, 10):

        for i in range(1, 10):

            dfs(str(i), keta)

    print(ans)



if __name__ == "__main__":

    main()

import sys

sys.setrecursionlimit(10**6)


def dfs(n, before):
    global cnt, K, ans, flag
    ints = int(before[-1])
    int1s = ints - 1
    ints1 = ints + 1
    if int1s >= 0:
        after1s = before + str(int1s)
        if n == 1:
            cnt += 1
        if cnt == K and flag == 0:
            ans = after1s
            flag = 1
            return
        if n >= 2:
            dfs(n - 1, after1s)
    afters = before + str(ints)
    if n == 1:
        cnt += 1
    if cnt == K and flag == 0:
        ans = afters
        flag = 1
        return
    if n >= 2:
        dfs(n - 1, afters)
    if ints1 <= 9:
        afters1 = before + str(ints1)
        if n == 1:
            cnt += 1
        if cnt == K and flag == 0:
            ans = afters1
            flag = 1
        if n >= 2:
            dfs(n - 1, afters1)


def main():
    global cnt, K, ans, flag
    K = int(eval(input()))
    if K <= 9:
        print(K)
        return
    cnt = 9
    flag = 0
    for n in range(1, 13):
        for s in range(1, 10):
            dfs(n, str(s))
            if flag == 1:
                break
        if flag == 1:
            break
    print(ans)


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**6)


def dfs(base, n):
    global K, cnt, ans, flag
    if flag:
        return
    if n == 0:
        cnt += 1
        if cnt == K:
            ans = int(base)
            flag = True
            return
    else:
        last = int(base[-1])
        for l in range(max(0, last - 1), min(10, last + 2)):
            nextbase = base + str(l)
            dfs(nextbase, n - 1)


def main():
    global K, ans, cnt, flag
    K = int(eval(input()))
    if K < 10:
        print(K)
        return
    leftK = int(str(K)[0])
    cnt = 9
    ans = 0
    flag = False
    for keta in range(1, 10):
        for i in range(1, 10):
            dfs(str(i), keta)
    print(ans)


if __name__ == "__main__":
    main()

-def dfs(n, before): -    global cnt, K, ans, flag -    ints = int(before[-1]) -    int1s = ints - 1 -    ints1 = ints + 1 -    if int1s >= 0: -        after1s = before + str(int1s) -        if n == 1: -            cnt += 1 -        if cnt == K and flag == 0: -            ans = after1s -            flag = 1 +def dfs(base, n): +    global K, cnt, ans, flag +    if flag: +        return +    if n == 0: +        cnt += 1 +        if cnt == K: +            ans = int(base) +            flag = True -        if n >= 2: -            dfs(n - 1, after1s) -    afters = before + str(ints) -    if n == 1: -        cnt += 1 -    if cnt == K and flag == 0: -        ans = afters -        flag = 1 -        return -    if n >= 2: -        dfs(n - 1, afters) -    if ints1 <= 9: -        afters1 = before + str(ints1) -        if n == 1: -            cnt += 1 -        if cnt == K and flag == 0: -            ans = afters1 -            flag = 1 -        if n >= 2: -            dfs(n - 1, afters1) +    else: +        last = int(base[-1]) +        for l in range(max(0, last - 1), min(10, last + 2)): +            nextbase = base + str(l) +            dfs(nextbase, n - 1) -    global cnt, K, ans, flag +    global K, ans, cnt, flag -    if K <= 9: +    if K < 10: +    leftK = int(str(K)[0]) -    flag = 0 -    for n in range(1, 13): -        for s in range(1, 10): -            dfs(n, str(s)) -            if flag == 1: -                break -        if flag == 1: -            break +    ans = 0 +    flag = False +    for keta in range(1, 10): +        for i in range(1, 10): +            dfs(str(i), keta)