#include <bits/stdc++.h>
using namespace std;
long long n;
long long po[50];
long long ans = 0;
int main() {
  cin >> n;
  long long m = n;
  po[0] = 1;
  int p = 1;
  while (po[p - 1] < n) {
    po[p] = po[p - 1] * 3;
    p++;
  }
  for (int(i) = int(0); i < int(50); i++)
    if (n % po[i] != 0) {
      cout << (n / po[i]) + 1 << '\n';
      return 0;
    } else if (n == po[i]) {
      cout << 1 << '\n';
      return 0;
    }
  return 0;
}
