#include <bits/stdc++.h>
using namespace std;
long long pw[40];
int main() {
  long long n;
  cin >> n;
  pw[0] = 1;
  for (int i = 1; i < 37; i++) pw[i] = pw[i - 1] * 3;
  for (int i = 1; i < 37; i++) {
    if (n % pw[i]) {
      cout << (long long)(n / pw[i]) + 1 << endl;
      break;
    }
  }
  return 0;
}
