#include <bits/stdc++.h>
inline long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * w;
}
using namespace std;
signed main() {
  long long n = read();
  while (n % 3 == 0) n /= 3;
  printf("%lld\n", (n + 2) / 3);
  return 0;
}
