#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  unsigned long long n;
  cin >> n;
  unsigned long long step = 1;
  while (n % 3 == 0) {
    n /= 3;
  }
  unsigned long long count3 = n / 3 + 1;
  cout << count3;
  return 0;
}
