import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    var N = sc.nextDouble()
    var sum = 0

    while (N != 0) {
      val a = math.pow(9, log9(N))
      val b = math.pow(6, log6(N))

      if (a > b) {
        N -= a
      } else {
        N -= b
      }
      sum += 1
    }

    println(sum)
  }

  def log9 (a: Double): Double = {
    (math.floor(math.log(a) / math.log(9)))
  }

  def log6 (a: Double): Double = {
    (math.floor(math.log(a) / math.log(6)))
  }
}