import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val K = sc.next().toInt()

        val runrun = mutableListOf<Long>(1, 2, 3, 4, 5, 6, 7, 8, 9)
        var p = 0
        var i = runrun.count()
        while (i < K) {
            val n = runrun[p]
            val r = n % 10
            if (r > 0) {
                runrun.add(n * 10 + r - 1)
                i++
            }
            runrun.add(n * 10 + r)
            i++
            if (r < 9) {
                runrun.add(n * 10 + r + 1)
                i++
            }
            p++
        }
        pw.println(runrun[K - 1])
    }
}
