import java.util.*

//package atcoder// TODO: ←消す

fun main(args: Array<String>) = ABC161D2.main()

object ABC161D2 {
    fun log(message: Any?) {
        println(message)// TODO: ←消す
    }

    fun main() {
        val K = readInt()

        val seq = generateSequence { LunSequence.next() }
        val ans = seq.drop(K - 1).first()
        println(ans)
    }

    object LunSequence {
        private val queue: Queue<Long> = ArrayDeque()

        init {
            queue.addAll(listOf(1, 2, 3, 4, 5, 6, 7, 8, 9))
        }

        fun next(): Long {
            val next = queue.poll()!!
            val bottom = next % 10

            val second = next * 10 + bottom
            val first = if (bottom != 0L) second - 1 else null
            val third = if (bottom != 9L) second + 1 else null

            val validNums = listOf(first, second, third)
                .filterNotNull()
            queue.addAll(validNums)

            return next
        }
    }
    /*####################################################################################*/

    fun readInt() = readLine()!!.toInt()
}