#include <bits/stdc++.h>
using namespace std;
long long table[40];
int main() {
  long long N;
  cin >> N;
  int i;
  table[0] = 1;
  for (i = 1; i < 40; i++) {
    table[i] = table[i - 1] * 3;
    if (table[i] > N) break;
  }
  int j = 0;
  while (j <= i && (N % table[j]) == 0) j++;
  long long res = N / table[j] + 1;
  cout << res << '\n';
  return 0;
}
