#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  long long n;
  while (~scanf("%lld", &n)) {
    while (n % 3 == 0) n /= 3;
    printf("%lld\n", n / 3 + 1);
  }
  return 0;
}
