#include <bits/stdc++.h>
using namespace std;
void Yahia74() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 1e5 + 74, OO = 0x3f3f3f3f, MOD = (int)1e9 + 7;
int main() {
  Yahia74();
  long long n;
  cin >> n;
  long long p = 3;
  while (n % p == 0) {
    p *= 3;
  }
  cout << n / p + 1;
  return 0;
}
