fun main(args: Array<String>) {
    val K = readLine()!!.toInt()


    val lunlunMap: MutableMap<Long, List<Int>> = mutableMapOf()
    repeat(10) { key ->
        val list = mutableListOf<Int>()
        repeat(10) { value ->
            if (Math.abs(key - value) <= 1) {
                list.add(value)
            }
        }
        lunlunMap += key.toLong() to list

    }
    val lunluns = mutableListOf<Long>()
    fun lunlun(n: Long, depth: Long, list: MutableList<Long>) {
        if (depth == 1L) {
            list.add(n)
            return
        }

        val n10 = n * 10L

        val tlun = lunlunMap[n % 10]!!.map { n10 + it }
        tlun.forEach {
            lunlun(it, depth - 1, list)
        }

    }

    var digit = 1L
    while (true) {
        repeat(9) {
            lunlun(it + 1L, digit, lunluns)
            if (lunluns.size >= K) {
                println(lunluns[K - 1])
                return
            }
        }
        digit++
    }
}



