object Main {
  def main(args : Array[String]) {
    val K = readLine().toInt
    var Q = new scala.collection.mutable.Queue[Long]
    for(i <- 1L to 9L) Q += i

    var x = 0L
    for(i <- 0 until K) {
      x = Q.dequeue
      val R = x % 10
      val E = 10 * x + R
      if(R != 0) Q += E - 1
      Q += E
      if(R != 9) Q += E + 1
    }

    println(x)
  }
}