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