#include <bits/stdc++.h>
using namespace std;
long long n;
int main(void) {
  long long ans;
  while (scanf("%I64d", &n) == 1) {
    ans = 1;
    if (n == 1)
      printf("1\n");
    else {
      while (n % ans == 0) {
        ans *= 3;
      }
      printf("%I64d\n", n / ans + 1);
    }
  }
  return 0;
}
