#include <bits/stdc++.h>
using namespace std;
int i, j, m;
long long n, k, an;
int main() {
  scanf("%I64d", &n);
  an = 1;
  for (k = 1; k <= n; k *= 3)
    if (n % k) an = max(an, n / k + 1);
  printf("%I64d\n", an);
  return 0;
}
