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