object Main {
  import scala.io.StdIn._
  import scala.collection.mutable.Queue
  def main(args: Array[String]): Unit = {
    var lunlunQueue = Queue((1L to 9L):_*)
    var k = readLine().toInt
    while (k != 1) {
      val h = lunlunQueue.dequeue()
      val l = h % 10L
      if (l != 0L) lunlunQueue.enqueue(h * 10L + l - 1)
      lunlunQueue.enqueue(h * 10L + l)
      if (l != 9) lunlunQueue.enqueue(h * 10L + l + 1)
      k -= 1
    }
    println(lunlunQueue.dequeue())
  }
}
