#include <bits/stdc++.h>
using namespace std;
vector<long long> p;
int main() {
  long long n;
  cin >> n;
  p.push_back(1);
  for (int i = 0; i < 80; i++) {
    p.push_back(p.back() * 3LL);
  }
  int ind = 0;
  while (p[ind] <= n) ind++;
  for (int i = 0; i < 80; i++) {
    if (n % p[i] != 0) {
      long long ans = n / p[i];
      if (n % p[i] != 0) ans++;
      cout << ans;
      return 0;
    }
  }
  return 0;
}
