import java.io.*; import java.util.*; class Main { public static void main(String args[])throws Exception { BufferedReader bu=new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb=new StringBuilder(); int N=300000,i,j,ans[]=new int[N+1]; ArrayList fac[]=new ArrayList[N+1]; for(i=0;i<=N;i++) { fac[i]=new ArrayList<>(); ans[i]=i; } for(i=2;i<=N;i++) for(j=2*i;j<=N;j+=i) fac[j].add(i); ans[1]=0; for(i=2;i<=N;i++) for(int x:fac[i]) ans[i]=Math.min(ans[i],ans[x]+i/x); int n=Integer.parseInt(bu.readLine()); System.out.println(ans[n]); } }