from collections import deque

K = int(eval(input()))



que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])



while K:

    if K == 1:

        ans = que.popleft()

        break

    K -= 1

    v = que.popleft()

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

        que.append(v + '0')

        que.append(v + '1')

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

        que.append(v + '8')

        que.append(v + '9')

    else:

        que.append(v + str(int(v[-1]) - 1))

        que.append(v + str(int(v[-1])))

        que.append(v + str(int(v[-1]) + 1))



print(ans)
from collections import deque





def main():

    K = int(eval(input()))

    que = deque(['1', '2', '3', '4', '5', '6', '7', '8', '9'])



    while K:

        if K == 1:

            ans = que.popleft()

            break

        K -= 1

        v = que.popleft()

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

            que.append(v + '0')

            que.append(v + '1')

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

            que.append(v + '8')

            que.append(v + '9')

        else:

            que.append(v + str(int(v[-1]) - 1))

            que.append(v + str(int(v[-1])))

            que.append(v + str(int(v[-1]) + 1))



    print(ans)



if __name__ == '__main__':

    main()
from collections import deque

K = int(eval(input()))
que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
while K:
    if K == 1:
        ans = que.popleft()
        break
    K -= 1
    v = que.popleft()
    if v[-1] == "0":
        que.append(v + "0")
        que.append(v + "1")
    elif v[-1] == "9":
        que.append(v + "8")
        que.append(v + "9")
    else:
        que.append(v + str(int(v[-1]) - 1))
        que.append(v + str(int(v[-1])))
        que.append(v + str(int(v[-1]) + 1))
print(ans)

from collections import deque


def main():
    K = int(eval(input()))
    que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
    while K:
        if K == 1:
            ans = que.popleft()
            break
        K -= 1
        v = que.popleft()
        if v[-1] == "0":
            que.append(v + "0")
            que.append(v + "1")
        elif v[-1] == "9":
            que.append(v + "8")
            que.append(v + "9")
        else:
            que.append(v + str(int(v[-1]) - 1))
            que.append(v + str(int(v[-1])))
            que.append(v + str(int(v[-1]) + 1))
    print(ans)


if __name__ == "__main__":
    main()

-K = int(eval(input())) -que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) -while K: -    if K == 1: -        ans = que.popleft() -        break -    K -= 1 -    v = que.popleft() -    if v[-1] == "0": -        que.append(v + "0") -        que.append(v + "1") -    elif v[-1] == "9": -        que.append(v + "8") -        que.append(v + "9") -    else: -        que.append(v + str(int(v[-1]) - 1)) -        que.append(v + str(int(v[-1]))) -        que.append(v + str(int(v[-1]) + 1)) -print(ans) + +def main(): +    K = int(eval(input())) +    que = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"]) +    while K: +        if K == 1: +            ans = que.popleft() +            break +        K -= 1 +        v = que.popleft() +        if v[-1] == "0": +            que.append(v + "0") +            que.append(v + "1") +        elif v[-1] == "9": +            que.append(v + "8") +            que.append(v + "9") +        else: +            que.append(v + str(int(v[-1]) - 1)) +            que.append(v + str(int(v[-1]))) +            que.append(v + str(int(v[-1]) + 1)) +    print(ans) + + +if __name__ == "__main__": +    main()