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

    if (k < 11) {
        println(k)
        return
    }

    lun.addAll(listOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"))

    var targetLun = lun
    var newLun = mutableSetOf<String>()

    while (lun.size < 100000) {
        newLun = mutableSetOf()
        targetLun.forEach {
            val fd = it.take(1).toInt()
            if (fd != 0) newLun.add("${fd-1}$it")
            if (fd != 9) newLun.add("${fd+1}$it")
            newLun.add("${fd}${it}")
        }
        lun.addAll(newLun)
        targetLun = newLun
    }

    println(lun.filter { it[0] != '0' }.map { it.toLong() }.sorted()[k-1])
}
