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