import java.util.ArrayDeque
import java.util.Queue

fun solve(num: Int): Long {
    val lunlun_queue: Queue<Long> = ArrayDeque()

    for(i in 1L..9L) {
        lunlun_queue.add(i)
    }
    var count = 0
    var result = 0L
    while(lunlun_queue.size > 0) {
        result = lunlun_queue.poll()
        count += 1
        val m = result % 10L
        if(m > 0L) {
            lunlun_queue.add(10L * result + (m - 1))
        }
        lunlun_queue.add(10L * result + m)
        if(m < 9) {
            lunlun_queue.add(10L * result + (m + 1))
        }
        if(count == num) {
            break
        }
    }
    return result
}

fun main(args: Array<String>) {
    val K = readLine()!!.toInt()
    val lunluns = solve(K)

    println(lunluns)
}