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