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