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