#include <bits/stdc++.h>
using namespace std;
long long n, w, r, m, h = 1, sum, mx = 0, ans = 1, a[100], b, c, a1,
                      mn = 100000090, a2, a3, a4, c1, c2, c3, c4;
string s;
int k = 1;
char ch;
int main() {
  cin >> n;
  while (n % 3 == 0) {
    n /= 3;
  }
  cout << n / 3 + 1;
  return 0;
}
