import itertools

import sys

import math

import numpy as np

import fractions

from collections import deque

from itertools import combinations

from functools import reduce

from functools import lru_cache

sys.setrecursionlimit(10**9)



def get_lcm(num):

    return reduce(lambda x,y:(x * y) // fractions.gcd(x, y), num, 1)



def main():

    K = int(eval(input()))

    if 0<=K<=10:

        print(K)

        exit()



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

    m = 0



    while len(lunlun) < K:

        x = lunlun[m]

        btm = x % 10



        if btm - 1 >= 0:

            lunlun.append(10*x+btm-1)



        lunlun.append(10*x+btm)



        if btm + 1 < 10:

            lunlun.append(10*x+btm+1)



        m += 1



    print((lunlun[::-1][len(lunlun)-K]))



if __name__ == "__main__":

  main()

import sys

sys.setrecursionlimit(10**9)



def main():

    K = int(eval(input()))

    if 0<=K<=10:

        print(K)

        exit()



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

    m = 0



    while len(lunlun) < K:

        x = lunlun[m]

        btm = x % 10



        if btm - 1 >= 0:

            lunlun.append(10*x+btm-1)



        lunlun.append(10*x+btm)



        if btm + 1 < 10:

            lunlun.append(10*x+btm+1)



        m += 1



    print((lunlun[::-1][len(lunlun)-K]))



if __name__ == "__main__":

  main()

import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache

sys.setrecursionlimit(10**9)


def get_lcm(num):
    return reduce(lambda x, y: (x * y) // fractions.gcd(x, y), num, 1)


def main():
    K = int(eval(input()))
    if 0 <= K <= 10:
        print(K)
        exit()
    lunlun = [i for i in range(1, 10)]
    m = 0
    while len(lunlun) < K:
        x = lunlun[m]
        btm = x % 10
        if btm - 1 >= 0:
            lunlun.append(10 * x + btm - 1)
        lunlun.append(10 * x + btm)
        if btm + 1 < 10:
            lunlun.append(10 * x + btm + 1)
        m += 1
    print((lunlun[::-1][len(lunlun) - K]))


if __name__ == "__main__":
    main()

import sys

sys.setrecursionlimit(10**9)


def main():
    K = int(eval(input()))
    if 0 <= K <= 10:
        print(K)
        exit()
    lunlun = [i for i in range(1, 10)]
    m = 0
    while len(lunlun) < K:
        x = lunlun[m]
        btm = x % 10
        if btm - 1 >= 0:
            lunlun.append(10 * x + btm - 1)
        lunlun.append(10 * x + btm)
        if btm + 1 < 10:
            lunlun.append(10 * x + btm + 1)
        m += 1
    print((lunlun[::-1][len(lunlun) - K]))


if __name__ == "__main__":
    main()

-import itertools -import math -import numpy as np -import fractions -from collections import deque -from itertools import combinations -from functools import reduce -from functools import lru_cache - - -def get_lcm(num): -    return reduce(lambda x, y: (x * y) // fractions.gcd(x, y), num, 1)