#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, mi = 1;
  cin >> n;
  while (1) {
    if (n % mi == 0)
      mi *= 3;
    else
      break;
  }
  cout << (n / mi) + 1;
  return 0;
}
