#include <bits/stdc++.h>
using namespace std;
const int inf = (int)(1e9);
const int mod = inf + 7;
const double pi = acos(-1.0);
const double eps = 1e-9;
long long n;
long long p = 1ll;
int main() {
  cin >> n;
  while (n % p == 0) {
    p *= 3ll;
  }
  cout << n / p + 1;
  return 0;
}
