#include <bits/stdc++.h>
using namespace std;
using namespace std::rel_ops;
const long long LL_MAX = ~((long long)~0 << 63);
template <class A>
inline bool Max(A& a, const A& b) {
  return a < b ? a = b, true : false;
}
template <class A>
inline bool Min(A& a, const A& b) {
  return b < a ? a = b, true : false;
}
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
  return out << '[' << p.first << ',' << p.second << ']';
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& v) {
  typename vector<A>::const_iterator it = v.begin(), end = v.end();
  if (it == end) return out << "[]";
  out << '[' << *it;
  while (++it != end) {
    out << ',' << *it;
  }
  return out << ']';
}
template <class A>
ostream& operator<<(ostream& out, const set<A>& st) {
  typename set<A>::const_iterator it = st.begin(), end = st.end();
  if (it == end) return out << "[]";
  out << '[' << *it;
  while (++it != end) {
    out << ',' << *it;
  }
  return out << ']';
}
template <class A>
ostream& operator<<(ostream& out, const multiset<A>& st) {
  typename multiset<A>::const_iterator it = st.begin(), end = st.end();
  if (it == end) return out << "[]";
  out << '[' << *it;
  while (++it != end) {
    out << ',' << *it;
  }
  return out << ']';
}
long long a[40];
int main(int argc, char** argv) {
  a[0] = 1;
  for (int i = 1; i < 40; ++i) a[i] = a[i - 1] * 3;
  long long k;
  while (cin >> k) {
    long long ans = 0;
    for (int i = 0;; ++i) {
      if (k % a[i] != 0) {
        Max(ans, k / a[i] + 1);
      }
      if (a[i] < 0 || a[i] > k) break;
    }
    cout << ans << endl;
  }
  return EXIT_SUCCESS;
}
