#include <bits/stdc++.h>
const double pi = acos(-1.0), eps = 1e-9;
const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
const int MO = (int)(1e9 + 7);
using namespace std;
int main() {
  long long n;
  cin >> n;
  while (n % 3 == 0) n /= 3;
  cout << n / 3 + 1 << endl;
}
