#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int te;
  cin >> te;
  long long int cg = 3;
  long long int ans = 1;
  while (cg < te) {
    if (te % cg != 0) {
      ans = te / cg;
      ans++;
      break;
    } else
      cg *= 3;
  }
  cout << ans << "\n";
  return 0;
}
