#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int main() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  unsigned long long int n, cur = 3, ans;
  cin >> n;
  while (n % cur == 0) {
    cur *= 3;
  }
  ans = (n + cur - 1) / cur;
  cout << ans << endl;
  return 0;
}
