import java.util.*

fun main(args: Array<String>) = abc161d()

fun abc161d() {
    val k = readLine()!!.toInt()

    val queue = ArrayDeque((1..9L).toList())
    var i = 1

    while (true) {
        val curr = queue.poll()
        if (i++ == k) return println(curr)
        val max = Math.min(curr % 10 + 1, 9)
        val min = Math.max(curr % 10 - 1, 0)
        queue.addAll((min..max).map { curr * 10 + it })
    }
}
