import scala.annotation.tailrec
import scala.io.StdIn._
object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val rank = readLong()
    if (rank == 0) return
    println(solve(rank))
    solve()
  }
  def countDigit(digit: Int): Long = {
    digit match {
      case 0 | 1 ⇒ 0
      case _ ⇒ 36 * ((1L << digit) - 2) + 9 * ((1L << (digit - 1)) - 1)
    }
  }
  def make(firstDigit: Int, digit: Int, rank: Long): List[Int] = {
    var rest = rank
    for (i ← 0 until 10) {
      if (i == firstDigit) {
        if (rest < 9 * ((1L << (digit - 1)) - 1)) {
          return firstDigit :: make(firstDigit, digit - 1, rest)
        }else {
          rest -= 9 * ((1L << (digit - 1)) - 1)
        }
      }else {
        if (rest < (1L << (digit - 1))) {
          val min = Math.min(firstDigit, i)
          val max = Math.max(firstDigit, i)
          return if (digit > 1) i::rest.toBinaryString.rightJust(digit - 1){'0'}.map{
            case '0' ⇒ min
            case '1' ⇒ max
          }.toList else List(i)
        }else {
          rest -= 1L << (digit - 1)
        }
      }
    }
    ???
  }
  def calDigit(rank: Long, digit: Int): Int = {
    if (rank < countDigit(digit)) {
      digit
    }else {
      calDigit(rank - countDigit(digit), digit + 1)
    }
  }
  def solve(rank: Long): String = {
    val digit = calDigit(rank - 1, 2)
    var rest = rank - 1 - (2 until digit).map(countDigit).sum
    for (i ← 1 until 10) {
      if (rest >= 9 * ((1L << (digit - 1)) - 1)) {
        rest -= 9 * ((1L << (digit - 1)) - 1)
      }else {
        return (i::make(i, digit - 1, rest)).mkString("")
      }
    }
    ???
  }
  implicit class StringExtension(val str: String) extends AnyVal {
    def rightJust(length: Int)(word: ⇒ Char): String = {
      if (str.length < length) word.toString * (length - str.length) + str
      else str
    }
  }
}
