"use strict";
function Main(input) {
  input = input.split("\n");
  const withdrawMoney = parseInt(input[0], 10);
  
  for(let nineCount = 0; nineCount < 6; nineCount++){
      if((withdrawMoney - 9**nineCount) < 0){
          let nineCounts = nineCount;
          let a = withdrawMoney - 9**nineCount;
      }
      for(let sixCount = 0; sixCount < 7; sixCount++){
          if(a - 6**sixCount < 0){
              let sixCounts = sixCount;
              let b = a - 6**sixCount; 
          }
      }
  }
  console.log(nineCounts);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf-8"));