https://www.acmicpc.net/problem/1463
n=int(input())
arr=[0 for _ in range(n+1)]
for i in range(2,n+1):
arr[i]=arr[i-1]+1
if(i%6==0): arr[i]=min(min(arr[i//3]+1,arr[i//2]+1),arr[i])
elif(i%3==0): arr[i]=min(arr[i//3]+1,arr[i])
elif(i%2==0): arr[i]=min(arr[i//2]+1,arr[i])
print(arr[n])