#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int pw = 1;
  while (n % pw == 0) pw *= 3;
  cout << (n + pw - 1) / pw << "\n";
  return 0;
}
