fun main(args: Array<String>) = abc161d()

fun abc161d() {
    val k = readLine()!!.toInt()

    val list = (1..9L).toMutableList()
    var before = list.toList()

    repeat(9) {
        val next = before.map { curr ->
            val max = Math.min(curr % 10 + 1, 9)
            val min = Math.max(curr % 10 - 1, 0)
            (min..max).map { curr * 10 + it }
        }.flatten()
        list.addAll(next)
        before = next
    }

    val answer = list.sorted()[k - 1]

    println(answer)
}
