import java.util.*
import java.math.*

private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrint: (String)->Unit = { msg -> System.err.println(msg) }


fun solveD(K:Int):Long {
    var que = LinkedList<Long>()
    for(i in 1L..9L) {
        que.push(i)
    }

    repeat(K-1) {
        val num = que.pollLast()
        val d1 = num%10
        if (d1 == 0L) {
            que.push((num*10+d1))
            que.push((num*10+d1+1))
        } else if (d1 == 9L) {
            que.push((num*10+d1-1))
            que.push((num*10+d1))
        } else {
            que.push((num*10+d1-1))
            que.push((num*10+d1))
            que.push((num*10+d1+1))
        }
    }

    return que.pollLast()
}


fun main(args: Array<String>) {
    val K = readInt()

    val ans = solveD(K)

    println(ans)
}
