#include <bits/stdc++.h>
using namespace std;
long long int log3(long long int n) {
  long long int ans = 0;
  while (n > 0) {
    n = n / 3;
    ans++;
  }
  return ans - 1;
}
int main() {
  long long int n;
  cin >> n;
  long long int ans = 0;
  for (long long int i = 3; i < LLONG_MAX; i *= 3) {
    if (n % i != 0) {
      ans = (n + i) / i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
