#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 20;
int c[N];
int main() {
  long long n;
  while (cin >> n) {
    long long m = n;
    int cnt = 0;
    memset(c, -1, sizeof(c));
    while (n) {
      c[cnt++] = n % 3;
      n /= 3;
    }
    int i = 0, g = 1;
    while (i < cnt && c[i] == 0) ++i, m /= 3;
    ++i, m /= 3;
    cout << m + 1 << endl;
  }
}
