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