fun main(args: Array<String>) {
  print(readLine()!!.toInt().let { n ->
    (0..n).map {
      var six = it * 6
      var nine = (n - it) * 9
      (1..7).map { six /= 6; nine /= 9; six % 6 + nine % 9 }.sum()
    }.min()
  })
}
