#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  unsigned long long n;
  while (cin >> n) {
    unsigned long long x = 1;
    while (1) {
      if (n % x) break;
      x *= 3;
    }
    unsigned long long r = (n - 1) / x + 1;
    cout << r << endl;
  }
  return 0;
}
