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