#include <bits/stdc++.h>
using namespace std;
vector<int> months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int MAX = 1e5 + 55;
const int inf = 1e9 + 77;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-7;
int main() {
  long long n;
  scanf("%I64d", &n);
  long long div = 3;
  while (n % div == 0) div *= 3;
  n /= div;
  ++n;
  printf("%I64d", n);
  return 0;
}
