#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int dx[] = {1, -1, 0, 0, 0, 0};
const int dy[] = {0, 0, 1, -1, 0, 0};
const int dz[] = {0, 0, 0, 0, 1, -1};
long long n;
int main() {
  scanf("%lld", &n);
  while (n % 3 == 0) n /= 3;
  printf("%lld\n", n / 3 + 1);
  return 0;
}
