#include <bits/stdc++.h>
using namespace std;
const long double pi = 2 * acos(0.0);
const long long prime = 31;
const long long inf = 1e18;
const long long mod = 1e9 + 9;
const long long maxn = 1e2 + 11;
long long n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  while (n % 3 == 0) {
    n /= 3;
  }
  cout << n / 3 + 1;
  return 0;
}
