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

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

        var a = listOf<Long>(1, 2, 3, 4, 5, 6, 7, 8, 9)
        var k = K
        while (k > 0) {
            if (k < a.count()) {
                pw.println(a[k - 1])
                return
            }
            val old = a
            a = old.flatMap { n ->
                val last = n % 10
                val nn = mutableListOf<Long>()
                if (last - 1 >= 0) nn.add(n * 10 + last - 1)
                nn.add(n * 10 + last)
                if (last + 1 <= 9) nn.add(n * 10 + last + 1)
                nn
            }
            k -= old.count()
        }
        pw.println(a[0])
    }
}
