#include <bits/stdc++.h>
using namespace std;
long long int arr[40], n, atual, ANS;
int main() {
  arr[0] = 1;
  for (int i = (1); i < (37); ++i) {
    arr[i] = 3 * arr[i - 1];
  }
  cin >> n;
  for (int i = (0); i < (37); ++i) {
    if (n % arr[i] != 0) {
      cout << (n / arr[i]) + 1 << endl;
      return 0;
    }
  }
  return 0;
}
