fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun rec(d: Int, value: Long, list: MutableList<Long>) {
    list.add(value)
    if (d > 10) return

    for (i in -1..1) {
        val addNum = (value % 10) + i
        if (addNum in 0..9) {
            rec(d + 1, value * 10 + addNum, list)
        }
    }
}

fun main() {
    val k = readInt()
    val list = mutableListOf<Long>()
    (1..9).forEach { rec(1, it.toLong(), list) }
    list.sort()
    println(list[k-1])
}