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