#include <bits/stdc++.h>
using namespace std;
int m, tmp, k, cnt;
long long a[40];
long long n;
long long ans;
int main() {
  a[0] = 1;
  for (int i = 1; i < 40; i++) {
    a[i] = a[i - 1] * 3;
  }
  scanf("%I64d", &n);
  int i = 1;
  while (n % a[i] == 0) i++;
  ans = n / a[i] + 1;
  printf("%I64d\n", ans);
  return 0;
}
