import copy

N=eval(input())



def nine(m):

	if m<9: return m

	for i in range(1000):

		t=9**i

		if t>m:

			t1=9**(i-1)

			return m-t1

def six(m):

	if m<6: return m

	for i in range(1000):

		t=6**i

		if t>m:

			t2=6**(i-1)

			return m-t2





Z=15

k=1<<Z



b=set()

for i in range(k):



	n=copy.deepcopy(N)

	ans=0

	for j in range(Z):

		if n<6:

			b.add(ans+n)

			break

		if i&(1<<j)!=0:

			#9

			n=nine(n)

			ans+=1

		else:

			#6

			n=six(n)

			ans+=1





print(min(b))





N=eval(input())



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

dp[0]=0



i=1



for i in range(1,8):

	for n in range(N):

		if n+ 9**i  <=N: 	dp[ n+ 9**i ]=min( dp[n]+1, dp[ n+9**i ] )

		if n+ 6**i  <=N: 	dp[ n+ 6**i ]=min( dp[n]+1, dp[ n+6**i ] )

		if n+ 1  <=N:	dp[ n+ 1 ]=min( dp[n]+1, dp[ n+1 ] )





print(dp[N])
import copy

N = eval(input())


def nine(m):
    if m < 9:
        return m
    for i in range(1000):
        t = 9**i
        if t > m:
            t1 = 9 ** (i - 1)
            return m - t1


def six(m):
    if m < 6:
        return m
    for i in range(1000):
        t = 6**i
        if t > m:
            t2 = 6 ** (i - 1)
            return m - t2


Z = 15
k = 1 << Z
b = set()
for i in range(k):
    n = copy.deepcopy(N)
    ans = 0
    for j in range(Z):
        if n < 6:
            b.add(ans + n)
            break
        if i & (1 << j) != 0:
            # 9
            n = nine(n)
            ans += 1
        else:
            # 6
            n = six(n)
            ans += 1
print(min(b))

N = eval(input())
dp = [float("inf") for i in range(N + 1)]
dp[0] = 0
i = 1
for i in range(1, 8):
    for n in range(N):
        if n + 9**i <= N:
            dp[n + 9**i] = min(dp[n] + 1, dp[n + 9**i])
        if n + 6**i <= N:
            dp[n + 6**i] = min(dp[n] + 1, dp[n + 6**i])
        if n + 1 <= N:
            dp[n + 1] = min(dp[n] + 1, dp[n + 1])
print(dp[N])

-import copy - - - -def nine(m): -    if m < 9: -        return m -    for i in range(1000): -        t = 9**i -        if t > m: -            t1 = 9 ** (i - 1) -            return m - t1 - - -def six(m): -    if m < 6: -        return m -    for i in range(1000): -        t = 6**i -        if t > m: -            t2 = 6 ** (i - 1) -            return m - t2 - - -Z = 15 -k = 1 << Z -b = set() -for i in range(k): -    n = copy.deepcopy(N) -    ans = 0 -    for j in range(Z): -        if n < 6: -            b.add(ans + n) -            break -        if i & (1 << j) != 0: -            # 9 -            n = nine(n) -            ans += 1 -        else: -            # 6 -            n = six(n) -            ans += 1 -print(min(b)) +dp = [float("inf") for i in range(N + 1)] +dp[0] = 0 +i = 1 +for i in range(1, 8): +    for n in range(N): +        if n + 9**i <= N: +            dp[n + 9**i] = min(dp[n] + 1, dp[n + 9**i]) +        if n + 6**i <= N: +            dp[n + 6**i] = min(dp[n] + 1, dp[n + 6**i]) +        if n + 1 <= N: +            dp[n + 1] = min(dp[n] + 1, dp[n + 1]) +print(dp[N])