#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int main() {
  long long n;
  scanf("%I64d", &n);
  long long m = 1;
  while (n % m == 0) m *= 3;
  printf("%I64d\n", (n + m - 1) / m);
  return 0;
}
