import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val k = in.readLine().toInt

    val queue = mutable.Queue.empty[Long]
    for (i <- 1 to 9) {
      queue += i
    }

    for (_ <- 0 until (k - 1)) {
      val v = queue.dequeue()
      val lv = v % 10
      if (lv != 0) {
        queue += v * 10 + lv - 1
      }
      queue += v * 10 + lv
      if (lv != 9) {
        queue += v * 10 + lv + 1
      }
    }

    out.println(queue.dequeue())

    out.flush()
  }
}
