#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  return (b == 0 ? a : gcd(b, a % b));
}
const int MAXN = 200005;
const int INF = 1000000000;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  while (cin >> n) {
    long long res = 0;
    for (int i = 0; i < 50; ++i) {
      int m = n % 3;
      if (m > 0) {
        res = n / 3 + 1;
        break;
      }
      n /= 3;
    }
    cout << res << endl;
  }
}
