process.stdin.resume();
process.stdin.setEncoding('utf8');
// Your code here!
var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
    var total = 0;
    var diff = Number(input);
    var c = 1;
    while(true){
        var i = 1;
        while(true){
            if (Math.pow(9, i) > diff) {
                break;
            }
            i++;
        }
        if (i > 1){
            total++;
            // console.log(diff);
            diff = diff - Math.pow(9, i - 1);
            // console.log('i:', i, diff);
        }
    
        
        var j = 1;
        while(true){
            if (Math.pow(6, j) > diff) {
                break;
            }
            j++;
        }
        if (j > 1) {
            total++;
            // console.log(diff);
            diff = diff - Math.pow(6, j - 1);
            // console.log('j', j, diff);
        }
        // console.log(diff);
        
        if (diff <= 9) {
            break;
        }
        // console.log('c:', c);
        c++;
    }
    if (diff > 9) {
        total++;
        diff = diff - 9;
    }
    if (diff > 6) {
        total++;
        diff = diff - 6;
    }
    // console.log(total, diff)
    total = total + diff;
    console.log(total)
});
