#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long pw = 1, n2 = n;
  while (n % 3 == 0) {
    pw++;
    n /= 3;
  }
  long long num = pow(3, pw);
  long long q = n2 / num, r = n2 % num;
  if (r) q++;
  cout << q;
  return;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  t = 1;
  while (t--) solve();
  return 0;
}
