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