fun pow(base: Int, exp: Int): Long{
    var ans=1L
    if(exp==0) return ans
    if (exp%2==1) ans*=base
    return ans*pow(base*base, exp/2)
}

fun main(args: Array<String>) {
    var k= readLine()!!.toInt()
    var a=Array(9){(it+1).toLong()}.toMutableList()
    var value: Long
    var last: Long
    for(i in 0 until k-1){
        value=a[i]
        last=value%10
        if (last==0L){
            a.add(10*value+last)
            a.add(10*value+last+1)
        }else if(last==9L){
            a.add(10*value+last-1)
            a.add(10*value+last)
        }else{
            a.add(10*value+last-1)
            a.add(10*value+last)
            a.add(10*value+last+1)
        }
    }
    println(a[k-1])
}