object Main {
  def main(args : Array[String]) {
    val K = readLine().toInt

    var Q = (9L to 1L by -1).toList

    var x = 0L
    for(i <- 0 until K) {
      x = Q.last
      Q = Q.init
      if(x % 10 != 0) Q ::= 10 * x + (x % 10) - 1
      Q ::= 10 * x + (x % 10)
      if(x % 10 != 9) Q ::= 10 * x + (x % 10) + 1
    }
    println(x)
  }
}