#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int buffer[1000005];
int main() {
cin.tie(NULL);
ios::sync_with_stdio(false);
int n;
cin >> n;
buffer[1] = 0;
buffer[2] = 1;
buffer[3] = 1;
if (n <= 3){
cout << buffer[n];
}else {
for (int i = 4 ; i <= n ; i++){
priority_queue<int, vector<int>, greater<int>> queue;
if ( i % 2 == 0){
queue.push(buffer[i /2]+1);
}
if (i % 3 == 0){
queue.push(buffer[i / 3]+1);
}
queue.push(buffer[i-1]+1);
buffer[i] = queue.top();
}
cout << buffer[n];
}return 0;
}