#include <bits/stdc++.h>
long long n;
int main() {
  scanf("%lld", &n);
  for (long long i = 3;; i *= 3) {
    if (n % i != 0) {
      printf("%lld\n", n / i + 1);
      return 0;
    }
  }
  return 0;
}
