object Main {
  import scala.io.StdIn._
  import scala.annotation.tailrec
  import scala.collection.mutable.Queue
  def main(args: Array[String]): Unit = {
    var lunlunQueue = Queue((1L to 9L):_*)
    var k = readLine().toInt
    @tailrec
    def loop(i: Int): Unit =
      if (i == 1) println(lunlunQueue.head)
      else {
        val h = lunlunQueue.dequeue()
        val l = h % 10L
        for {
          i <- Seq(l - 1, l, l + 1)
          if i >= 0L && i < 10L
        } {
          lunlunQueue.enqueue(h * 10L + (i))
        }
        loop(i - 1)
      }
    loop(k)
  }
}
