#include <bits/stdc++.h>
using namespace std;
long long int N, C, D, E;
int main() {
  int ans;
  while (scanf("%I64d", &N) == 1) {
    if (N % 3 == 0) {
      C = 1;
      while (1) {
        if (N % C == 0)
          C *= 3;
        else {
          printf("%I64d\n", N / C + 1);
          return 0;
        }
      }
    } else
      printf("%I64d\n", N / 3 + 1);
  }
  return 0;
}
