https://www.acmicpc.net/problem/1463
using System;
class Program
{
static void Main() {
string s=Console.ReadLine();
int n=int.Parse(s);
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]);
}
Console.Write(arr[n]);
}
}