object Main extends App {
	val N = scala.io.StdIn.readInt
	val a = scala.collection.mutable.Queue.empty[Long]

	for(x<-1L to 9L) a.enqueue(x)

	for(t<-1 to N-1){
		val x = a.dequeue()
		val tp = 10L*x + (x % 10L)
		if(x%10L != 0L) a.enqueue(tp - 1L)
		a.enqueue(tp)
		if(x%10L != 9L) a.enqueue(tp + 1L)
	}

	println(a.dequeue())
}