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