import numpy as np

from math import log

N=int(eval(input()))



L=[1]

for i in range(1,N):

    if 6**i<=N:

        L.append(6**i)

    else:

        break

for i in range(1,N):

    if 9**i<=N:

        L.append(9**i)

    else:

        break

L=np.array(L)

dp=np.ones((N+1))*100000

dp[0]=0

dp[1]=1

for i in range(2,N+1):

    dp[i]=(dp[i-L]+1).min()



print((int(dp[N])))
N=int(eval(input()))

L=[1]

for i in range(1,100):

    a=6**i

    if a<=100000:

        L.append(a)

    else:

        break

for i in range(1,100):

    a=9**i

    if a<=100000:

        L.append(a)

    else:

        break

dp=[1000000]*(N+1)

dp[0]=0

for i in range(1,N+1):

    sub=10**5

    for l in L:

        if i-l>=0:

            sub=min(sub, dp[i-l]+1)

    dp[i]=sub



print((dp[N]))
import numpy as np
from math import log

N = int(eval(input()))
L = [1]
for i in range(1, N):
    if 6**i <= N:
        L.append(6**i)
    else:
        break
for i in range(1, N):
    if 9**i <= N:
        L.append(9**i)
    else:
        break
L = np.array(L)
dp = np.ones((N + 1)) * 100000
dp[0] = 0
dp[1] = 1
for i in range(2, N + 1):
    dp[i] = (dp[i - L] + 1).min()
print((int(dp[N])))

N = int(eval(input()))
L = [1]
for i in range(1, 100):
    a = 6**i
    if a <= 100000:
        L.append(a)
    else:
        break
for i in range(1, 100):
    a = 9**i
    if a <= 100000:
        L.append(a)
    else:
        break
dp = [1000000] * (N + 1)
dp[0] = 0
for i in range(1, N + 1):
    sub = 10**5
    for l in L:
        if i - l >= 0:
            sub = min(sub, dp[i - l] + 1)
    dp[i] = sub
print((dp[N]))

-import numpy as np -from math import log - -for i in range(1, N): -    if 6**i <= N: -        L.append(6**i) +for i in range(1, 100): +    a = 6**i +    if a <= 100000: +        L.append(a) -for i in range(1, N): -    if 9**i <= N: -        L.append(9**i) +for i in range(1, 100): +    a = 9**i +    if a <= 100000: +        L.append(a) -L = np.array(L) -dp = np.ones((N + 1)) * 100000 +dp = [1000000] * (N + 1) -dp[1] = 1 -for i in range(2, N + 1): -    dp[i] = (dp[i - L] + 1).min() -print((int(dp[N]))) +for i in range(1, N + 1): +    sub = 10**5 +    for l in L: +        if i - l >= 0: +            sub = min(sub, dp[i - l] + 1) +    dp[i] = sub +print((dp[N]))