import java.util.*

fun main(args: Array<String>) {
    val K = readInt()

    val que = ArrayDeque<Long>()
    que.addAll((1L..9L).toList())
    var t = 0
    while (true) {
        t++
        val q = que.pop()
        if (t == K) {
            println(q)
            return
        }
        val run = q % 10
        if (run > 0) que.add(10 * q + run - 1)
        que.add(10 * q + run)
        if (run < 9) que.add(10 * q + run + 1)
    }
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
