#include <bits/stdc++.h>
using namespace std;
long long three(long long n) {
  long long cnt = 0;
  while (n % 3 == 0) {
    n /= 3;
    ++cnt;
  }
  return cnt;
}
long long power[10010];
int main() {
  long long n, res, tmp = 1;
  int i = 0;
  while (tmp <= 1e18) {
    power[i] = tmp;
    ++i;
    tmp *= 3;
  }
  while (cin >> n) {
    if (n % 3 == 0)
      cout << n / power[three(n) + 1] + 1 << " \n";
    else {
      res = n / 3 + 1;
      cout << res << " \n";
    }
  }
  return 0;
}
