#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int main() {
  long long n;
  cin >> n;
  for (long long mon = 3;; mon *= 3) {
    if (mon >= n) {
      cout << 1 << endl;
      break;
    }
    if (n % mon != 0) {
      cout << (n / mon) + 1 << endl;
      break;
    }
  }
  return 0;
}
