#include <bits/stdc++.h>
using namespace std;
const long long maxn = (long long)1e17;
long long a[65];
int main() {
  a[0] = 1;
  for (int i = 1; i < 65; i++) {
    a[i] = a[i - 1] * 3;
    if (a[i] > maxn) break;
  }
  long long n;
  scanf("%I64d", &n);
  int i;
  for (i = 0; i < 64; i++) {
    if (n % a[i] != 0) break;
  }
  printf("%I64d\n", n / a[i] + 1);
  return 0;
}
