#include <iostream>
#include <vector>
#include <queue>
using namespace std;

const int INF = 1 << 30;

int main()
{
  const int MAX = 1000000+1;
  vector<int> dp(MAX, INF);
  dp[1] = 0;
  queue<int> que;
  que.push(1);
  while (!que.empty()) {
    int num = que.front();
    que.pop();

    int even = num * 2;
    if (even < MAX && dp[even] > dp[num]+1) {
      dp[even] = dp[num]+1;
      que.push(even);
    }

    int odd = (num-1) / 3;
    if (odd > 0 && odd < MAX && dp[odd] > dp[num]+1) {
      dp[odd] = dp[num]+1;
      que.push(odd);
    }
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    cout << dp[n] << endl;
  }
  return 0;
}