#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int maxn = 3000000;
const long long MANY = 1000000;
int main() {
  long long n;
  cin >> n;
  while (n % 3 == 0) n /= 3;
  long long ans = (n % 3 ? 1 : 0) + n / 3;
  cout << ans << endl;
  return 0;
}
