object Main {
  import scala.io.StdIn
  def main(args: Array[String]): Unit = {
    def isRunRunStr(charSequence: List[Char]): Boolean = {
      def go(prev: Char, rest: List[Char]): Boolean =
        rest match {
          case Nil => true
          case head :: tail if Math.abs(Character.digit(head, 10) - Character.digit(prev, 10)) <= 1 =>
            go(head, tail)
          case _ => false
        }
      go(charSequence.head, charSequence.tail)
    }
    def isRunRun(n: BigDecimal) = {
      if (n < 13) true
      else isRunRunStr(n.toString().toCharArray.toList)
    }
    val naturalNumber = Stream.iterate(BigDecimal.valueOf(1L))(v => v + 1L)
    val runrun = naturalNumber.filter(isRunRun)
    val n = StdIn.readLine().toInt
    println(runrun(n - 1))
  }
}
