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 

def main():

    K = int(readline())

    dq = deque() 

    cnd = []

    for i in range(1, 10):

        dq.append(i)

        cnd.append(i)

    

    while len(dq)>0:

        v = dq.popleft()

        r = v%10 

        if r == 0:

            nx = v*10

            dq.append(nx)

            cnd.append(nx)

            nx = v*10+1

            dq.append(nx)

            cnd.append(nx)

        elif r == 9:

            nx = v*10+8

            dq.append(nx)

            cnd.append(nx)

            nx = v*10+9

            dq.append(nx)

            cnd.append(nx)

        else:

            nx = v*10+(r-1)

            dq.append(nx)

            cnd.append(nx)

            nx = v*10+r

            dq.append(nx)

            cnd.append(nx)

            nx = v*10+(r+1)

            dq.append(nx)

            cnd.append(nx)

        if len(cnd) > K: 

            break

    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


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


if __name__ == "__main__":
    main()

+from collections import deque -    dq = [] +    dq = deque() +    cnd = [] -    for i in range(K): -        v = dq[i] +        cnd.append(i) +    while len(dq) > 0: +        v = dq.popleft() -        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) +        if r == 0: +            nx = v * 10 +            dq.append(nx) +            cnd.append(nx) +            nx = v * 10 + 1 +            dq.append(nx) +            cnd.append(nx) +        elif r == 9: +            nx = v * 10 + 8 +            dq.append(nx) +            cnd.append(nx) +            nx = v * 10 + 9 +            dq.append(nx) +            cnd.append(nx) -            dq.append(v * 10 + (r - 1)) -            dq.append(v * 10 + r) -            dq.append(v * 10 + (r + 1)) -    print((dq[K - 1])) +            nx = v * 10 + (r - 1) +            dq.append(nx) +            cnd.append(nx) +            nx = v * 10 + r +            dq.append(nx) +            cnd.append(nx) +            nx = v * 10 + (r + 1) +            dq.append(nx) +            cnd.append(nx) +        if len(cnd) > K: +            break +    print((cnd[K - 1]))