#include <bits/stdc++.h>
using namespace std;
long long coin[40];
int main() {
  long long n, ans = 1;
  cin >> n;
  long long pw = 3;
  coin[0] = 1;
  for (long long i = 1;; i++) {
    coin[i] = coin[i - 1] * pw;
    if (coin[i] > n) break;
  }
  for (long long i = 1;; i++) {
    if (coin[i] > n) break;
    if (n % coin[i] == 0) continue;
    ans = (n / coin[i] + 1);
    break;
  }
  printf("%lld\n", ans);
  return 0;
}
