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