#include <bits/stdc++.h>
using namespace std;
long long a[40];
int main() {
  ios::sync_with_stdio(0);
  long long i, j, l, m, p, q, t, r, ll, rr, s1, s2, f, n;
  a[0] = 1;
  t = 0;
  cin >> n;
  for (i = 1; a[i - 1] <= n; i++) {
    a[i] = a[i - 1] * 3;
    if (n % a[i]) t = max(t, n / a[i] + 1);
  }
  cout << t << endl;
  return 0;
}
