#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, min = 1, temp, t;
  long long count = 1;
  cin >> n;
  temp = n;
  while (n > 0) {
    t = n % 3;
    if (t > 0) {
      min *= 3;
      count += temp / min;
      break;
    }
    min *= 3;
    n /= 3;
  }
  cout << count << endl;
  return 0;
}
