fun main(args: Array<String>) {
    var k = readLine()!!.toInt()
    var lunlun = mutableListOf<Long>(1, 2, 3, 4, 5, 6, 7, 8, 9)
    var tmpArray = mutableListOf<Long>()
    var q:Long
    var qt:Long
    if (k < 10) {
        println(lunlun[k-1])
    } else {
        k -= 9
        loop@while (true) {
            while (!lunlun.isEmpty()) {
                q = lunlun[0]
                lunlun.removeAt(0)
                qt = q*10
                q %= 10
                when(q) {
                    0L -> {
                        repeat(2){tmpArray.add(qt+it)}
                        k -= 2
                    }
                    9L -> { 
                        repeat(2){tmpArray.add(qt+it+8)}
                        k -= 2
                    }
                    else -> {
                        repeat(3){tmpArray.add(qt+it+q-1)}
                        k -= 3
                    }
                }
                if (k <= 0) {
                    break@loop
                }
            }
            lunlun = tmpArray.toMutableList()
            tmpArray.clear()
        }
        println(tmpArray[tmpArray.size+k-1])
    }
}
