#include <bits/stdc++.h>
using namespace std;
int main() {
  long long l;
  cin >> l;
  if (l % 3 != 0) {
    cout << l / 3 + 1;
    return 0;
  }
  for (long long i = 3; i <= l; i *= 3)
    if (l == i) {
      cout << 1;
      return 0;
    }
  for (long long i = 9; i <= l; i *= 3)
    if (l % i != 0) {
      cout << l / i + 1;
      return 0;
    }
}
