#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
int main() {
  ios_base::sync_with_stdio(false);
  long long int n;
  cin >> n;
  while (!(n % 3)) n /= 3;
  cout << n / 3 + 1 << endl;
  return 0;
}
