#include <bits/stdc++.h>   using namespace std;   template <class _T>   inline _T sqr(const _T& first) {     return first * first;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795L;   const long double EPS = 5e-12;   char TEMPORARY_CHAR;   const int INF = 1e9;   inline void input(int& a) {     a = 0;     while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) &&            (TEMPORARY_CHAR !=  - )) {     }     char neg = 0;     if (TEMPORARY_CHAR ==  - ) {       neg = 1;       TEMPORARY_CHAR = getchar();     }     while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) {       a = 10 * a + TEMPORARY_CHAR -  0 ;       TEMPORARY_CHAR = getchar();     }     if (neg) a = -a;   }   inline void out(int a) {     if (!a) putchar( 0 );     if (a < 0) {       putchar( - );       a = -a;     }     char s[10];     int i;     for (i = 0; a; ++i) {       s[i] =  0  + a % 10;       a /= 10;     }     for (int j = (i)-1; j >= 0; j--) putchar(s[j]);   }   inline int nxt() {     int(ret);     input((ret));     ;     return ret;   }   char can[8][8];   bool check(const vector<int>& a) {     for (int i : a)       for (int j : a)         if (!can[i][j]) return false;     return true;   }   int main() {     long long n;     cin >> n;     long long tri = 1;     while (n % tri == 0) tri *= 3;     cout << (n + tri - 1) / tri << endl;     return 0;   }   