import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from collections import deque

cnt = 0

def main():

    K = int(readline())

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



    dq = deque()

    for i in range(1, 10):

        dq.append(i)



    cnt = 0 

    while len(dq)>0:

        cnt += 1

        x = dq.popleft()

        v = x%10

        if v==0:

            for i in (0, 1):

                nx = 10*x+i

                cnd.append(nx)

                dq.append(nx)

        elif v == 9:

            for i in (-1, 0):

                nx = 10*x+9+i

                cnd.append(nx)

                dq.append(nx)

        else:

            for i in (-1, 0, 1):

                nx = 10*x+v+i

                cnd.append(nx)

                dq.append(nx)

        if cnt == K:

            break 

    cnd.sort()

    print((cnd[K-1]))

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

def main():

    K = int(readline())

    dq = []

    for i in range(1, 10):

        dq.append(i)

    for i in range(K):

        v = dq[i]

        r = v%10

        if r == 9:

            dq.append(v*10+8)

            dq.append(v*10+9)

        elif r == 0:

            dq.append(v*10)

            dq.append(v*10+1)

        else:

            dq.append(v*10+(r-1))

            dq.append(v*10+r)

            dq.append(v*10+(r+1))

    print((dq[K-1]))



if __name__ == '__main__':

    main()



import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

cnt = 0


def main():
    K = int(readline())
    cnd = [i for i in range(1, 10)]
    dq = deque()
    for i in range(1, 10):
        dq.append(i)
    cnt = 0
    while len(dq) > 0:
        cnt += 1
        x = dq.popleft()
        v = x % 10
        if v == 0:
            for i in (0, 1):
                nx = 10 * x + i
                cnd.append(nx)
                dq.append(nx)
        elif v == 9:
            for i in (-1, 0):
                nx = 10 * x + 9 + i
                cnd.append(nx)
                dq.append(nx)
        else:
            for i in (-1, 0, 1):
                nx = 10 * x + v + i
                cnd.append(nx)
                dq.append(nx)
        if cnt == K:
            break
    cnd.sort()
    print((cnd[K - 1]))


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    K = int(readline())
    dq = []
    for i in range(1, 10):
        dq.append(i)
    for i in range(K):
        v = dq[i]
        r = v % 10
        if r == 9:
            dq.append(v * 10 + 8)
            dq.append(v * 10 + 9)
        elif r == 0:
            dq.append(v * 10)
            dq.append(v * 10 + 1)
        else:
            dq.append(v * 10 + (r - 1))
            dq.append(v * 10 + r)
            dq.append(v * 10 + (r + 1))
    print((dq[K - 1]))


if __name__ == "__main__":
    main()

-from collections import deque - -cnt = 0 -    cnd = [i for i in range(1, 10)] -    dq = deque() +    dq = [] -    cnt = 0 -    while len(dq) > 0: -        cnt += 1 -        x = dq.popleft() -        v = x % 10 -        if v == 0: -            for i in (0, 1): -                nx = 10 * x + i -                cnd.append(nx) -                dq.append(nx) -        elif v == 9: -            for i in (-1, 0): -                nx = 10 * x + 9 + i -                cnd.append(nx) -                dq.append(nx) +    for i in range(K): +        v = dq[i] +        r = v % 10 +        if r == 9: +            dq.append(v * 10 + 8) +            dq.append(v * 10 + 9) +        elif r == 0: +            dq.append(v * 10) +            dq.append(v * 10 + 1) -            for i in (-1, 0, 1): -                nx = 10 * x + v + i -                cnd.append(nx) -                dq.append(nx) -        if cnt == K: -            break -    cnd.sort() -    print((cnd[K - 1])) +            dq.append(v * 10 + (r - 1)) +            dq.append(v * 10 + r) +            dq.append(v * 10 + (r + 1)) +    print((dq[K - 1]))