#include <bits/stdc++.h>
using namespace std;
long long p[99];
int main() {
  long long n;
  cin >> n;
  p[0] = 1;
  for (int i = 1; (p[i] = p[i - 1] * 3) <= n; i++)
    ;
  int i = 0;
  while (n % p[i] == 0) i++;
  cout << n / p[i] + 1;
}
