#include <bits/stdc++.h>
long long n;
int main() {
  int i;
  scanf("%lld", &n);
  if (n % 3 != 0) {
    printf("%lld\n", n / 3 + 1);
    return 0;
  }
  long long temp = n / 3, aa = 3;
  while (temp % aa == 0) {
    aa *= 3;
  }
  temp /= aa;
  printf("%lld\n", temp + 1);
  return 0;
}
