#include <bits/stdc++.h>
using namespace std;
const int N = 3e5;
const int INF = 1e9 + 9;
const int B = 1e9 + 7;
long long n;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  long long pwr = 1;
  for (;;) {
    long long x = (n + (pwr - 1)) / pwr;
    if (n % pwr != 0) {
      cout << x << "\n";
      return 0;
    }
    if (x == 1) {
      cout << x << "\n";
      return 0;
    }
    if (x == 2 && pwr * 3 < n) {
      cout << x << "\n";
      return 0;
    }
    pwr *= 3;
  }
  assert(0);
  return 0;
}
