output_description: If at least x operations are required to withdraw exactly N yen in total,
  print x.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
attempt: iN = int(input())
  
  """
  9**i
  0 1
  1 9
  2 81
  3 729
  4 6561
  5 59049
  
  1 6
  2 36
  3 216
  4 1296
  5 7776
  6 46656
  
  1 6
  1 9
  2 36
  2 81
  3 216
  3 729
  4 1296
  4 6561
  5 7776
  6 46656
  5 59049
  
  """
  
  aG = [531441, 59049, 46656, 7776, 6561, 1296, 729, 216, 81, 36, 9, 6, 1]
  # aG = [1]
  # for i in range(1,7):
  #   aG.append(9**i)
  #   aG.append(6**i)
  # aG.sort(reverse=True)
  # iL = len(aG)
  iL = 13
  aC = [0] * iL
  iC = 0
  for i in range(iL):
      iPe = 0
      a = aG[i]
      while a <= iN:
          iN -= a
          iPe += 1
          iC += 1
      aC[i] = iPe
      # 2*9 + 3 = 1*9 + 2*6 # 5個 -> 3個
      if aC[10] >= 2 and aC[12] >= 3:
          iC -= 2
  print(iC)
  
problem_description: Statement
  
  To make it difficult to withdraw money, a certain bank allows its customers to
  withdraw only one of the following amounts in one operation:
  
    * 1 yen (the currency of Japan)
  
    * 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
  
    * 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
  
  At least how many operations are required to withdraw exactly N yen in total?
  
  It is not allowed to re-deposit the money you withdrew.
samples: [{"input": "127", "output": "4\n    \n\nBy withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw\n127 yen in four operations.\n\n* * *"}, {"input": "3", "output": "3\n    \n\nBy withdrawing 1 yen three times, we can withdraw 3 yen in three operations.\n\n* * *"}, {"input": "44852", "output": "16"}]