#include <bits/stdc++.h>
using namespace std;
long long possible[40];
long long power(long long x, long long y) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret *= x;
    y >>= 1;
    x *= x;
  }
  return ret;
}
int main() {
  for (int i = 0; i < 37; i++) possible[i] = power(3, i);
  long long n;
  cin >> n;
  long long answer = 0, check;
  for (int i = 0; i < 37; i++) {
    check = n / possible[i];
    if (n % possible[i] != 0) answer = max(answer, check + 1);
  }
  cout << answer;
  return 0;
}
