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