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