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