#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, w = 1;
  scanf("%lld", &n);
  vector<long long> v(1, w);
  while (w <= LLONG_MAX / 3) {
    w *= 3;
    v.push_back(w);
  }
  long long res = 1;
  for (size_t i = 0; i < v.size(); ++i) {
    if (n % v[i] == 0) continue;
    res = max(res, n / v[i] + 1);
  }
  printf("%lld\n", res);
  return 0;
}
