function count_price(count, price){
  if(price==0){return count;}
  const numbers = array_of_6_9();
  for(var i=0;i<numbers.length;i++){
    if(numbers[i]<=price){
//console.log(numbers[i]);
return count_price(count+1, price-numbers[i])}
  }
}

function array_of_6_9(){
  var arr_6 = [];
  var tmp = 1;
  for(var i=0;i<6;i++){
    tmp*=6;
    arr_6.push(tmp)
  }

  var arr_9 = [];
  var tmp = 1;
  for(var i=0;i<5;i++){
    tmp*=9;
    arr_9.push(tmp)
  }
  var result = [1];
  result = result.concat(arr_6);
  result = result.concat(arr_9);

  result.sort(function(a,b){return b-a;})

  return result;
}

function main(input){
  const lines = input.split('\n');
  const N = parseInt(lines[0]);

  times_6_9_numbers = array_of_6_9();
  var result = count_price(0, N);
  console.log(result);
}

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