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