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