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: n = int(input())
  
  ar = []
  
  for l in range(2):  # 59049
      abc = n - (59049 * l)
      if abc < 0:
          break
      for k in range(3):  # 46656
          abc = n - (46656 * k + 59049 * l)
          if abc < 0:
              break
          for j in range(6):  # 7776
              abc = n - (776 * j + 46656 * k + 59049 * l)
              if abc < 0:
                  break
              for h in range(3):  # 1296,6
                  abc = n - (1296 * h + 7776 * j + 46656 * k + 59049 * l)
                  if abc < 0:
                      break
                  for g in range(4):  # 729,9
                      abc = n - (729 * g + 1296 * h + 7776 * j + 46656 * k + 59049 * l)
                      if abc < 0:
                          break
                      for f in range(3):  # 216,5(4)
                          abc = n - (
                              216 * f
                              + 729 * g
                              + 1296 * h
                              + 7776 * j
                              + 46656 * k
                              + 59049 * l
                          )
                          if abc < 0:
                              break
                          for e in range(4):  # 81
                              abc = n - (
                                  81 * e
                                  + 216 * f
                                  + 729 * g
                                  + 1296 * h
                                  + 7776 * j
                                  + 46656 * k
                                  + 59049 * l
                              )
                              if abc < 0:
                                  break
                              for d in range(5):  # 36
                                  abc = n - (
                                      36 * d
                                      + 81 * e
                                      + 216 * f
                                      + 729 * g
                                      + 1296 * h
                                      + 7776 * j
                                      + 46656 * k
                                      + 59049 * l
                                  )
                                  if abc < 0:
                                      break
                                  for c in range(4):  # 9
                                      abc = n - (
                                          9 * c
                                          + 36 * d
                                          + 81 * e
                                          + 216 * f
                                          + 729 * g
                                          + 1296 * h
                                          + 7776 * j
                                          + 46656 * k
                                          + 59049 * l
                                      )
                                      if abc < 0:
                                          break
                                      for b in range(3):  # 6
                                          abc = n - (
                                              6 * b
                                              + 9 * c
                                              + 36 * d
                                              + 81 * e
                                              + 216 * f
                                              + 729 * g
                                              + 1296 * h
                                              + 7776 * j
                                              + 46656 * k
                                              + 59049 * l
                                          )
                                          if abc < 0:
                                              break
                                          for a in range(6):  # 1
                                              abc = n - (
                                                  1 * a
                                                  + 6 * b
                                                  + 9 * c
                                                  + 36 * d
                                                  + 81 * e
                                                  + 216 * f
                                                  + 729 * g
                                                  + 1296 * h
                                                  + 7776 * j
                                                  + 46656 * k
                                                  + 59049 * l
                                              )
                                              if abc < 0:
                                                  break
                                              if abc % 6561 == 0 and abc >= 0:
                                                  i = abc // 6561
                                                  ar.append(
                                                      a
                                                      + b
                                                      + c
                                                      + d
                                                      + e
                                                      + f
                                                      + g
                                                      + h
                                                      + i
                                                      + j
                                                      + k
                                                      + l
                                                  )
  print(min(ar))
  
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"}]