#include<iostream>
using namespace std;
int main(){
int vec[1000001];
int num;
cin>>num;
vec[1] = 0;
for(int i=2;i<=num;i++){
int n = 1000001;
if(i%3==0){
n = min(n, vec[i/3]+1);
}
if(i%2 == 0){
n = min(n, vec[i/2]+1);
}
n = min(n, vec[i-1]+1);
vec[i] = n;
}
cout<<vec[num];
}