#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int MaxN = int(1e5) + 256;
const int MOD = int(1e9) + 7;
int main() {
  long long n;
  cin >> n;
  while (n % 3 == 0) n /= 3;
  cout << n / 3 + 1;
  return 0;
}
