import java.util.Deque
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val queue: Deque<Long> = ArrayDeque()
    for (i in 1..9) queue.add(i.toLong())
    var res: Long = 0L
    for (i in 1..n) {
        res = queue.poll()!!
        if (i == n) {
            println(res)
            return
        }
        if (res%10L != 0L) queue.add((res*10)+(res%10)-1)
        queue.add((res*10)+(res%10))
        if (res%10L != 9L) queue.add((res*10)+(res%10)+1)
    }
}