#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, num, s, res;
  long long i, tab[50];
  cin >> n;
  tab[0] = 1;
  for (i = 1; i <= 40; i++) tab[i] = tab[i - 1] * 3;
  s = 3;
  while (1) {
    if (n % s) {
      res = n / s + 1;
      break;
    } else
      s = s * 3;
  }
  cout << res << endl;
  return 0;
}
