#include <bits/stdc++.h>
using namespace std;
long long table[39];
int main() {
  long long n;
  int i;
  table[0] = 1;
  table[1] = 3;
  for (i = 2; i <= 38; ++i) table[i] = table[i - 1] * 3;
  scanf("%I64d", &n);
  i = 38;
  if (n % 3 != 0) {
    printf("%I64d\n", 1LL * n / 3 + 1);
    return 0;
  }
  i = 2;
  while (n % table[i] == 0) i++;
  if (table[i] >= n) {
    printf("1\n");
    return 0;
  }
  printf("%I64d\n", n / table[i] + 1);
  return 0;
}
