#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int n, m, N, M, I, J;
int di[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dj[] = {0, 0, 1, -1, 1, -1, 1, -1};
bool val(const int& i, const int& j) {
  return i >= 0 && i < I && j >= 0 && j < J;
}
int comp(const double& a, const double& b) {
  if (fabs(a - b) < eps) return 0;
  return a < b ? -1 : 1;
}
int main() {
  long long x, ret = 0;
  while (cin >> x) {
    for (long long y = 1;; y *= 3) {
      long long z = x / y;
      if (x % y) {
        z++;
        ret = max(ret, z);
      }
      if (y > x) break;
    }
    cout << ret << endl;
  }
  return 0;
}
