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