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