fun main(args: Array<String>) {
    val k = readLine()!!.split(" ").map { it.toInt() }[0]
    var queue = mutableListOf<Long>()
    for (i in 0 until 9){
        queue.add(i.toLong() + 1)
    }
    for (i in 0 until k){
        val x = queue[0]
        queue.minusAssign(queue[0])
        if (i == k - 1) println(x)
        if (x % 10 != 0L){
            queue.add(10 * x + (x % 10) - 1)
        }
        queue.add(10 * x + (x % 10))
        if (x % 10 != 9L){
            queue.add(10 * x + (x % 10) + 1)
        }
    }
}