#include <bits/stdc++.h>
long long int result(long long int n) {
  while (!(n % 3)) {
    n /= 3;
  }
  return (n + 2) / 3;
}
int main() {
  long long int n;
  std::cin >> n;
  std::cout << result(n) << '\n';
}
