#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  while (cin >> n) {
    long long m = 1;
    for (; n % m == 0;) {
      m = m * 3;
    }
    n = n / m;
    n++;
    cout << n << endl;
  }
}
