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