#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  long long n, a, b, ans;
  long long arr[50];
  arr[0] = 1;
  for (i = 1; i < 40; i++) arr[i] = arr[i - 1] * 3;
  scanf("%I64d", &n);
  for (i = 0; i < 40; i++) {
    if (n == arr[i]) {
      printf("1\n");
      break;
    } else if (n % arr[i] != 0) {
      b = arr[i];
      a = (n / arr[i]) + 1;
      printf("%I64d\n", a);
      break;
    }
  }
  return 0;
}
