fun main(args:Array<String>) {
	val n = readLine()!!.toInt()
	val x6 = listOf(6, 36, 216, 1296, 7776, 46656)
	val x9 = listOf(9, 81, 729, 6561, 59049)
	val step = (x6+x9+1).sorted()
	val dp = IntArray(n+1){it}
	for(i in dp.indices){
		step.filter{i+it<=n}.forEach {
			dp[i+it]=Math.min(dp[i+it],dp[i]+1)
		}
	}
	println(dp[n])
}