#include <bits/stdc++.h>
int main() {
  long long c, n, k;
  c = 1;
  scanf("%I64d", &n);
  for (int i = 1;; i++) {
    if (n % c == 0)
      c *= 3;
    else
      break;
  }
  k = n / c + 1;
  if (c > n)
    printf("%d\n", 1);
  else
    printf("%I64d\n", k);
  return 0;
}
