#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
template <class T>
bool get_max(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
long long n;
long long ans = 0;
long long coin[40];
int main() {
  coin[1] = 1;
  for (int i = 2; i < 40; ++i) {
    coin[i] = coin[i - 1] * 3;
  }
  cin >> n;
  if (n % 3 == 0) {
    for (int i = 2; i < 40; ++i) {
      if (n % coin[i] != 0) {
        ans = n / coin[i] + 1;
        break;
      }
    }
  } else {
    ans = n / 3 + 1;
  }
  cout << ans << endl;
  return 0;
}
