import scala.collection.mutable

object Main extends App {
  val k = scala.io.StdIn.readInt()
  var x: Long = 0L

  var queue = mutable.Queue(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L)
  for (_ <- 1 to k) {
    x = queue.dequeue
    val b = x % 10L

    if (b != 0) {
      queue.enqueue(10L * x + (b - 1L))
    }

    queue.enqueue(10L * x + b)

    if (b != 9) {
      queue.enqueue(10L * x + (b + 1L))
    }
  }

  println(x)
}
