#include <bits/stdc++.h>
using namespace std;
vector<int> conv(long long k) {
  vector<int> res;
  while (k != 0) {
    res.push_back(k % 3);
    k /= 3;
  }
  return res;
}
long long power(int pow) {
  long long res = 1;
  while (pow != 0) {
    res *= 3;
    pow--;
  }
  return res;
}
int main() {
  int pow = 0;
  long long N;
  vector<int> tree;
  cin >> N;
  tree = conv(N);
  while (tree[pow] == 0 && pow < tree.size()) pow++;
  pow++;
  cout << (N / power(pow)) + 1 << endl;
  return 0;
}
