#include <bits/stdc++.h>
using namespace std;
template <typename T, typename L>
inline bool smax(T &x, L y) {
  return x < y ? (x = y, true) : false;
}
template <typename T, typename L>
inline bool smin(T &x, L y) {
  return y < x ? (x = y, true) : false;
}
long long n;
int main() {
  cin >> n;
  while (!(n % 3)) {
    n /= 3;
  }
  return cout << (n + 2) / 3 << '\n', false;
}
