#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  int val = (int)cbrt(n) + 1;
  for (int i = 0; i <= val; i++) {
    long long int power = pow(3, i);
    if (n % power != 0) {
      cout << (n / power) + 1 << endl;
      return 0;
    }
  }
  return 0;
}
