#include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define N 1000002
vector<int> cl(N,0);
class Queue{
	vector<int> v;
	int low;
	int high;
public:
	Queue():v(N,0),low(N-1),high(N-1){}
	void push(const int &t){
		v[low]=t;
		--low;
	}
	void pop(int &t){
		t=v[high];
		--high;
	}
	bool empty(){
		return high==low;
	}
} ;
int main()
{
	Queue q;
	cl[1]=0;
	q.push(1);
	while( !q.empty() ){
		int t;
		q.pop(t);
		if( t*2<N ){
			if( cl[t*2]==0 ){
				cl[t*2]=cl[t]+1;
				q.push(t*2);
			}
		}
		if( (t-1)%3==0&&t>1 ){
			if( cl[(t-1)/3]==0 ){
				cl[(t-1)/3]=cl[t]+1;
				q.push((t-1)/3);
			}
		}
	}

	while(true){
		int n;
		
		cin>>n;
		if(n==0)break;

		cout << cl[n] << endl;
	}
	return 0;
}