#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 0, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
long long n;
int main() {
  while (~scanf("%lld", &n)) {
    for (long long i = 3;; i *= 3) {
      if (n % i != 0) {
        long long ans = n / i + 1;
        printf("%lld\n", ans);
        break;
      }
    }
  }
  return 0;
}
