fun main(args: Array<String>) {
    val k = readLine()?.toInt() ?: return
    if (k <= 10) {
        println(k.toLong())
        return
    }
    var current = mutableListOf(1, 0)
    var direction = true
    var next = false
    0.until(k - 10).forEach {
        next = false
        direction = true
        var index = current.size - 1
        while (!next) {
            val v = current[index]
            if (index == 0) {
                // 左端
                if (v + 1 >= 10) {
                    current = (listOf(1) + current).toMutableList()
                } else {
                    current[index] += 1
                }
                direction = false
                index++
            } else if (index == current.size - 1) {
                // 右端
                val p = current[index - 1]
                if (direction) {
                    if (p - v <= -1 || v == 9) {
                        index--
                    } else {
                        current[index] += 1
                        next = true
                    }
                } else {
                    current[index] = Math.max(p - 1, 0)
                    next = true
                }
            } else {
                // それ以外
                val p = current[index - 1]
                val n = current[index + 1]
                if (direction) {
                    if ((p - v <= -1 || v - n >= 1) || v == 9) {
                        index--
                    } else {
                        current[index] += 1
                        direction = false
                        index++
                    }
                } else {
                    current[index] = Math.max(p - 1, 0)
                    index++
                }
            }
        }
    }
    val value = current.fold(0L, { a, b ->
        a * 10 + b
    })
    println(value)
}
