#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
static inline int Rint() {
  struct X {
    int dig[256];
    X() {
      for (int i = '0'; i <= '9'; ++i) dig[i] = 1;
      dig['-'] = 1;
    }
  };
  static X fuck;
  int s = 1, v = 0, c;
  for (; !fuck.dig[c = getchar()];)
    ;
  if (c == '-')
    s = 0;
  else if (fuck.dig[c])
    v = c ^ 48;
  for (; fuck.dig[c = getchar()]; v = v * 10 + (c ^ 48))
    ;
  return s ? v : -v;
}
template <typename T>
static inline void cmax(T& a, const T& b) {
  if (b > a) a = b;
}
template <typename T>
static inline void cmin(T& a, const T& b) {
  if (b < a) a = b;
}
const int maxn = 100005;
int main() {
  long long n;
  scanf("%I64d", &n);
  if (n <= 2) {
    puts("1");
    return 0;
  }
  long long dig[64];
  int top = 0;
  for (long long t = n; t; t /= 3) dig[top++] = t % 3;
  long long ans = 1;
  long long w = 1;
  for (int i = 0; i <= top - 1; ++i, w *= 3) {
    if (n % w == 0) continue;
    long long t = n / w + 1;
    cmax(ans, t);
  }
  cout << ans << endl;
  return 0;
}
