#include <bits/stdc++.h>
using namespace std;
const long long oo = 300000000000000005LL;
long long mon[40], n;
int m;
int main() {
  mon[0] = 1;
  m = 0;
  while (mon[m] * 3LL < oo) {
    mon[m + 1] = mon[m] * 3LL;
    m++;
  }
  while (cin >> n) {
    if (n == 1LL)
      cout << 1 << endl;
    else {
      long long res = 0LL;
      for (int i = 1; i <= m; i++) {
        if (n % mon[i] != 0) {
          res = max(res, (n / mon[i]) + 1LL);
        }
      }
      cout << res << endl;
    }
  }
  return 0;
}
