#include <bits/stdc++.h>
using namespace std;
unsigned long long p3[37];
int main(void) {
  unsigned long long n;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 3) {
    cout << 1 << endl;
    return 0;
  }
  p3[0] = 1;
  for (int i = 0; i < 36; ++i) {
    p3[i + 1] = p3[i] * 3;
  }
  int ind = 0;
  for (ind = 0; ind < 37; ++ind) {
    if (n % p3[ind] != 0) break;
  }
  cout << (n / p3[ind]) + 1 << endl;
  return 0;
}
