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