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