#include <bits/stdc++.h>
using namespace std;
long long n, pw[40];
int main() {
  pw[0] = 1;
  for (int i = 1; i < 36; i++) {
    pw[i] = pw[i - 1] * 3;
    if (pw[i] >= 100000000000000000) break;
  }
  cin >> n;
  int l, h;
  for (int i = 0; i < 36; i++) {
    if (n <= pw[i]) {
      cout << 1;
      return 0;
    } else if (n % pw[i] != 0) {
      cout << n / pw[i] + 1;
      return 0;
    }
  }
  cout << 1;
  return 0;
}
