#include <bits/stdc++.h>
using namespace std;
long long hehe[50];
int main() {
  int i;
  hehe[0] = 3;
  for (i = 1; i < 50; i++) hehe[i] = 3 * hehe[i - 1];
  long long n;
  while (cin >> n) {
    i = 0;
    while (n % hehe[i] == 0) {
      i++;
    }
    cout << n / hehe[i] + 1 << endl;
  }
}
