https://www.acmicpc.net/problem/1463
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int arr[]=new int[n+1];
for(int i=2;i<=n;i++){
arr[i]=arr[i-1]+1;
if(i%6==0) arr[i]=Math.min(Math.min(arr[i/3]+1,arr[i/2]+1),arr[i]);
else if(i%3==0) arr[i]=Math.min(arr[i/3]+1,arr[i]);
else if(i%2==0) arr[i]=Math.min(arr[i/2]+1,arr[i]);
}
System.out.print(arr[n]);
}
}