import java.lang.Math

fun main(args: Array<String>) {
    val k = readInputLine().toInt()

    var cnt = 0
    val arr = LongArray(k)

    fun dfs(lastDig: Long, current: Long, base: Long, remDigits: Int) {
        if (cnt >= k) {
            return
        }
        if (remDigits == 0) {
            arr[cnt] = current
            cnt++
            return
        }
        for (i in LongRange(Math.max(lastDig - 1L, 0L), Math.min(lastDig + 1L, 9L))) {
            dfs(i, current * 10L + i, base * 10L, remDigits - 1)
        }
    }

    for (dig in 0..20) {
        for (i in LongRange(1L, 9L)) {
            dfs(i, i, 10L, dig)
        }
        if (cnt >= k) {
            println(arr[k - 1])
            return
        }
    }
}

fun readInputLine(): String {
    return readLine()!!
}
