var main = function(input) {
N = parseInt(input);
var array = [1,6,9,6*6,9*9,6*6*6,9*9*9,6*6*6*6,9*9*9*9,6*6*6*6*6,9*9*9*9*9];
var     i = 10;
var count =  0;
  
    while(N > 0){
      if(array[i]>N){
    		i--;
    } else if(N>=array[i]){
        N = N - array[i];
        count++
    } 
    }
        console.log(count);

    return 0; 
}

main(require("fs").readFileSync("/dev/stdin", "utf8").trim());