#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
  cin >> n;
  if (n <= 3) {
    cout << 1 << endl;
    return 0;
  }
  long long t = 3;
  while (n % t == 0) t *= 3;
  n = n / t + 1;
  cout << n << endl;
  return 0;
}
