import java.io.PrintWriter
import java.util.*

fun main() {
    val reader = System.`in`.bufferedReader()
    val writer = PrintWriter(System.out, false)

    var tokenizer: StringTokenizer = StringTokenizer("")

    fun next(): String {
        while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextLine() = reader.readLine()

    fun PrintWriter.solve() {
        var k = nextInt()

        var q = ArrayDeque<Long>((1L..9L).toList())
        var cnt = 0

        while (cnt <= k){
            var cur = q.pollFirst()
//            println(cur)
            cnt++

            if (cnt == k){
                print(cur)
                break
            }

            var lastDigit = cur%10
            if(lastDigit != 0L) q.addLast(cur*10 + lastDigit - 1)
            q.addLast(cur*10 + lastDigit)
            if(lastDigit != 9L)q.addLast(cur*10 + lastDigit + 1)

        }


    }

    writer.solve()
    writer.flush()


}


