n = int(eval(input()))

v = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]

dp = [float("inf") for i in range(n+1)]

dp[0] = 0

for i in range(n):

	for j in v:

		if i + j <= n:

			dp[i+j] = min(dp[i+j], dp[i]+1)

print(("{}".format(dp[n])))

def ds(a, b):

	return a if a<b else ds(a//b,b)+a%b

ans = float('inf')

n = int(eval(input()))

for i in range(n+1):

	ans = min(ans,ds(i,6)+ds(n-i,9))

print(ans)
n = int(eval(input()))
v = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049]
dp = [float("inf") for i in range(n + 1)]
dp[0] = 0
for i in range(n):
    for j in v:
        if i + j <= n:
            dp[i + j] = min(dp[i + j], dp[i] + 1)
print(("{}".format(dp[n])))

def ds(a, b):
    return a if a < b else ds(a // b, b) + a % b


ans = float("inf")
n = int(eval(input()))
for i in range(n + 1):
    ans = min(ans, ds(i, 6) + ds(n - i, 9))
print(ans)

+def ds(a, b): +    return a if a < b else ds(a // b, b) + a % b + + +ans = float("inf") -v = [1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049] -dp = [float("inf") for i in range(n + 1)] -dp[0] = 0 -for i in range(n): -    for j in v: -        if i + j <= n: -            dp[i + j] = min(dp[i + j], dp[i] + 1) -print(("{}".format(dp[n]))) +for i in range(n + 1): +    ans = min(ans, ds(i, 6) + ds(n - i, 9)) +print(ans)