const fs = require("fs");

function Main(input){
    input = parseInt(input);
    var count = 0;
    var array = [6,9,36,81,216,729,1296,6561,7776,46656,59049];
    while(input != 0){
        for(i = 10; i >= 0; i--){
            if(input == array[i]){
                count ++;
                input = input - array[i];
                i = 10;
            }else if(input > array[i]){
                count ++;
                input = input - array[i];
                i = 10;
            }else if(input < 6){
                count = count + input;
                input = 0;
            }
        }
    }
    console.log(count);
}

Main(fs.readFileSync("/dev/stdin", "utf8"));