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