#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  if (n % 3 == 0) {
    long long cur = 1;
    while (n % cur == 0) cur *= (long long)3;
    cout << n / cur + 1;
    return 0;
  }
  cout << n / 3 + 1;
}
