#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    long long int i, j, k, y, n, x, m, a, b, ans = 0, sum = 0, cnt = 1;
    string s, st, taj = "YES";
    long long int chk = INT_MAX;
    cin >> n;
    while (n % cnt == 0) {
      cnt *= 3;
      sum = (n + cnt - 1) / cnt;
    }
    cout << sum << endl;
  }
  return 0;
}
