function main(input) {
  const inputs = input.split('\n')
  const [K] = inputs[0].split(' ').map(Number)
  // console.log(K)
  const a = [1,2,3,4,5,6,7,8,9]
  let p = 0
  while(true) {
    // console.log(K, p, a.length, a)
    if (K <= a.length) {
      // console.log('OK:', K, a.length)
      console.log(a[K - 1])
      return 
    }
    const len = a.length
    for(let i = p; i < len; i++) {
      for (let j = -1; j <= 1; j++) {
        let k = String(a[i])
        let d = a[i] % 10 + j
        if (d < 10 && 0 <= d) {
          const nn = k + String((a[i] % 10) + j)
          a.push(Number(nn))
        }
      }
      p++
    }
  }
  // console.log(a)
  // console.log('finished')
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

