#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 30;
const int NN = 20;
const int TMXN = 1e5 * 8 + 1;
const int INF = 1e9 + 7;
long long n;
long long x = 1;
int main() {
  scanf("%I64d", &n);
  while (n % x == 0) {
    x *= 3LL;
  }
  cout << n / x + 1;
  return 0;
}
