#include <bits/stdc++.h>
using namespace std;
long long n, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  while (cin >> n) {
    x = 1;
    while (n % x == 0) x *= 3;
    cout << (n + x - 1) / x << '\n';
  }
}
