#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7;
const long double EPS = 1e-9;
long long binpow(long long a, long long b) {
  long long m = MOD;
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long modInverse(long long a, long long m = MOD) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  if (n == 1) {
    cout << 1;
    exit(0);
  }
  vector<long long> pow;
  long long x = 1;
  pow.push_back(1);
  while (x <= 1e17 + 1) {
    x *= 3ll;
    pow.push_back(x);
  }
  for (auto &i : pow) {
    if ((n % i) != 0) {
      cout << (n - 1) / i + 1;
      exit(0);
    }
  }
  return 0;
}
