import java.util.Scanner
import java.lang.Math.*
import kotlin.system.exitProcess

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val k = scn.nextInt()
	if (k<=12) {
		println(k)
		exitProcess(0)
	}
	var cnt = 9
	var dig = 2
	while(true){
		cnt = cur(k, dig, cnt)
		dig++
	}
}

fun cur(k: Int, dig: Int, cnt: Int, num: IntArray = IntArray(dig){-1}, iDig: Int = 0): Int {
	var newCnt = cnt
	val range = when(iDig){
		0 -> 1..9
		else -> max(num[iDig-1]-1, 0)..min(num[iDig-1]+1, 9)
	}
	if (iDig!=dig-1){
		for (d in range){
			num[iDig] = d
			newCnt = cur(k, dig, newCnt, num, iDig+1)
		}
	}else {
		newCnt += range.count()
		if (newCnt>=k) {
			num[num.lastIndex] = range.toList()[k-cnt-1]
			println(num.joinToString(separator = ""))
			exitProcess(0)
		}
	}
	return newCnt
}