function Main(input){

N=parseInt(input);

answer = 0;

var array = [1];

a6 = 6;
a9 = 9;
b = 0;

for (; array[array.length - 1] <= 100000;) {
    if (a6 < a9) {
        array.push(a6);
        a6 = a6 * 6;
    }
    else if (a6 > a9) {
        array.push(a9);
        a9 = a9 * 9;
    }
    else {
        array.push(a6);
        a6 = a6 * 6;
        a9 = a9 * 9;
    }
}

P = array.length - 1;
for (; N > 0;) {
    F = 0;
    answer++
    for (; F == 0;) {
        if (array[P] <= N) {
            N = N - array[P];
            F = 1;
        }
        else {
            P = P - 1;
        }
    }
}

console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
