import Foundation
class Node {
  var val: Int64
  var next: Node?
  init(val: Int64) {
    self.val = val
  }
}

class Queue {
  var head: Node?
  var tail: Node?
  init(){}
  func enqueue(val: Int64) {
    let node = Node(val: val)
    if head == nil {
      head = node
      tail = head
    } else {
      tail!.next = node
      tail = node
    }
  }
  func dequeue() -> Int64 {
    let val = self.head!.val
    self.head = self.head!.next
    if self.head == nil {
      self.tail = nil
    }
    return val
  }
}
func solve(K: Int64) -> Int64 {
  if K < 10 {
    return K
  }
  let queue = Queue()
  for i in 1...9 {
    queue.enqueue(Int64(i))
  }
  var count: Int64 = 9
  var result: Int64 = -1
  while count < K {
    let top = queue.dequeue()
    let last = top % 10
    for start in last-1...last+1 {
      if start < 0 || start > 9 {
        continue
      }
      let next = top * 10 + start
      queue.enqueue(next)
      count += 1
      if count == K {
        result = next
        break
      }
    }
  }
  return result
}

let input = readLine()!
let info = input.componentsSeparatedByString(" ")
let K = Int64(info[0])!

print(solve(K))
