#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64777216")
using namespace std;
double Eps = 1e-9;
double Pi = 3.14159265358979323846;
double E = 2.71828182845904523536;
int mod = 1000 * 1000 * 1000 + 7;
vector<long long> P;
long long M = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 200;
int main() {
  long long n;
  cin >> n;
  long long val = 1;
  for (;;) {
    P.push_back(val);
    val *= 3;
    if (val > M) {
      P.push_back(val);
      break;
    }
  }
  for (int i = 0; i < P.size(); i++) {
    if (n % P[i] != 0) {
      cout << n / P[i] + 1 << endl;
      return 0;
    }
  }
  return 0;
}
