#include<bits/stdc++.h>
using namespace std;
int minSteps(int n , int dp[])
{
dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <=n; ++i) {
if(i%2==0)
{
dp[i] =min(dp[i/2] , dp[i-1]) + 1;
}
else if(i%3==0)
{
dp[i] = min(dp[i/3] , dp[i-1]) + 1;
}
else
{
dp[i] = dp[i-1] + 1;
}
}
return dp[n];
}
int main() {
int n;
cin >> n;
int dp[10005] = {0};
cout<<minSteps(n, dp);
}
//What is wrong in the above code for minimum steps to one ? It is giving wrong answer for n = 30;