#include <bits/stdc++.h>
using namespace std;
const int NMax = 1000001;
const int cntTree = 262145;
const long double eps = 1e-9;
const double PI = 3.141592653589793238462;
const int MD = (int)1e9 + 7;
FILE *stream;
long long n;
int main() {
  cin >> n;
  long long t = 1;
  while (n % t == 0) t *= 3;
  cout << n / t + 1 << endl;
  return 0;
}
