#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream& operator<<(ostream& out, const pair<T, TT>& p) {
  out << p.first << " " << p.second;
  return out;
}
template <typename T, typename TT>
istream& operator>>(istream& in, pair<T, TT>& s) {
  in >> s.first >> s.second;
  return in;
}
int main() {
  long long n;
  cin >> n;
  long long a = 3;
  for (;;) {
    if (n % a == 0) {
      a *= 3;
    } else {
      cout << n / a + 1 << endl;
      break;
    }
  }
  return 0;
}
