import kotlin.math.*
import java.util.*

fun main(args: Array<String>) {
  val k = readLine()!!.toInt()
  val q = ArrayDeque<String>()
  (1..9).forEach { q += it.toString() }
  var x = ""
  repeat(k) {
    x = q.remove()
    val y = x.last()
    if (y != '0') q += x + (y - 1)
    q += x + y
    if (y != '9') q += x + (y + 1)
  }
  println(x)
}
