#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long max_res = -1;
  if (n <= 3)
    cout << "1\n";
  else {
    for (long long i = 3; true; i *= 3) {
      if (n % i != 0) max_res = max(max_res, n / i + 1);
      if (i > n) break;
    }
    cout << max_res << endl;
  }
}
