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