var k: Int = 0
var foundCount: Int = 0
var lastFound: Long = 0

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

    var keta = 0

    while(true) {
        keta += 1

        for (i in (1..9)) {
            recur(keta, listOf(i))

            if (foundCount == k) {
                break
            }
        }

        if (foundCount == k) {
            break
        }
    }

    println(lastFound)
}

fun recur(keta: Int, nos: List<Int>) {
    if (keta == 1) {
        foundCount += 1
        lastFound = nos.map {it.toString()}.joinToString("") {it}.toLong()
        return
    }

    val nums = (Math.max(nos.last() - 1, 0)..Math.min(nos.last() + 1, 9))
    for (i in nums) {
        recur(keta - 1, nos.plus(i))
        if (foundCount == k) {
            break
        }
    }
}