fun main(args: Array<String>) {
    val K = nextInt()
    val ans = mutableListOf<Long>()
    (0 .. 9).forEach { ans.add(it.toLong()) }
    var p = 1
    while (p < K) {
        val x = ans[p++]
        for (a in -1 .. 1) {
            val d = x % 10 + a
            if (d < 0 || d > 9) continue
            ans.add(10 * x + d)
        }
    }
    println(ans[K])
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
