#include <bits/stdc++.h>
using namespace std;
template <class C>
inline C sqr(C x) {
  return x * x;
}
template <class C>
inline C lg2(C x) {
  return C(log2(x));
}
template <class C>
inline C lbt(C x) {
  return x & (-x);
}
template <class C>
inline C cbt(C x) {
  return x ? (x & 1) + cbt(x >> 1) : 0;
}
template <class C>
inline bool have(C x, C i) {
  return (x >> i) & 1;
}
long long t[40];
int main() {
  t[0] = 1;
  for (int i = 1; i <= 36; i++) t[i] = t[i - 1] * 3;
  long long n;
  cin >> n;
  for (int i = 1; i <= 36; i++) {
    if (n % t[i] != 0) {
      cout << n / t[i] + 1 << endl;
      break;
    }
  }
  return 0;
}
