let arr = [59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
var N = Int(readLine()!)!
var ans = 0
while N > 0 {
    for i in arr {
        if i <= N {
            N -= i
            ans += 1
            break
        }
    }
}
print(ans)