#include <bits/stdc++.h>
using namespace std;
unsigned long long Pow(unsigned long long x, unsigned long long y) {
  unsigned long long res = 1;
  while (y > 0) {
    if (y & 1) res *= x;
    x *= x;
    y >>= 1;
  }
  return res;
}
int main() {
  unsigned long long n;
  cin >> n;
  if (n % 3 == 0) {
    for (unsigned long long i = 2; i <= 100; i++) {
      unsigned long long p = Pow(3, i);
      if (n % p != 0) {
        unsigned long long ans;
        ans = n / p + 1;
        cout << ans << endl;
        break;
      }
    }
  } else
    cout << (n / 3) + 1 << endl;
  return 0;
}
