Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen.One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get?The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of n marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least n marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want.

The single line contains a single integer n (1 ≤ n ≤ 1017). Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with.

NoteIn the first test case, if a buyer has exactly one coin of at least 3 marks, then, to give Gerald one mark, he will have to give this coin. In this sample, the customer can not have a coin of one mark, as in this case, he will be able to give the money to Gerald without any change.In the second test case, if the buyer had exactly three coins of 3 marks, then, to give Gerald 4 marks, he will have to give two of these coins. The buyer cannot give three coins as he wants to minimize the number of coins that he gives.

#include <bits/stdc++.h>
using namespace std;
long long n,t=1,kn=3;

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    scanf("%I64d",&n);
    while(n%kn==0) kn*=3;
    printf("%I64d\n",n/kn+1);
	return 0;
}

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
  long _begin_time = clock();
#endif
  ll n;
  while (~scanf("%lld", &n))
  {
    while (n % 3 == 0)
      n /= 3;
    printf("%lld\n", n / 3 + 1);
  }

#ifndef ONLINE_JUDGE
  long _end_time = clock();
  printf("time = %ld ms.", _end_time - _begin_time);
#endif
  return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;

const int N = 1000;
ll n;
int main()
{
    while(cin >> n)
    {
        while(n % 3 == 0) n /= 3;
        cout << n/3 + 1 << endl;
    }
    return 0;
}

#include<stdio.h>

__int64 n;

int main()
{
scanf("%I64d",&n);
while(n%3==0) n/=3;
printf("%I64d\n",n/3+1);
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define endl '\n'

ll pow_mod(ll a, ll e) {
  ll ret = 1LL;
  while (e > 0) {
    if (e & 1) ret *= a;
    e >>= 1;
    if (e > 0) {
      a *= a;
    }

  }
  return ret;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);

  ll n;
  cin >> n;

  ll ans = 0;
  for (int exp = 36; exp >= 0 && n >= 1; --exp) {
    ll x = pow_mod(3, exp);
    ll cur = (n+x-1) / x;
    if (n%x) {
      ans = max(ans, cur);
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    long long int n;
    cin>>n;
    while(n%3==0){
        n/=3;
    }
    cout<<n/3+1;
}

#include<iostream>
#include<cstdio>
using namespace std;
long long n;
int main()
{
	cin >> n;
	while(n%3==0)
	{
		n=n/3;
	}
	cout << n/3+1 << endl;
	return 0;
}

/************************************************************************************************************

	AUTHOR : coderhead_42

	FILE NAME : secrets.cpp

	CREATION DATE : Sat 27 Jul 2013 02:17:14 PM IST

	LAST MODIFIED : Sat 27 Jul 2013 04:32:23 PM IST

*************************************************************************************************************/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>

using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<vector <int> > VVI;
typedef vector<vector <int> >::iterator VVII;
typedef vector<string> VSTR;
typedef vector<string>::iterator VSTRI;
typedef string STR;
typedef string::iterator STRI;
typedef pair<int,int> PII;
typedef list<int> LI;
typedef list<int>::iterator LII;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;

#define INF (int)1e9
#define LINF (long long)1e18
#define EPS 1e-9
#define PI 3.1415926
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int) (x).size())
#define LEN(X) ((int)(X.length()))
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORi(i,a,b) for (i=a;i<b;i++)
#define ROF(i,a,b) for(int i=a-1;i>=b;i--)
#define ROFi(i,a,b) for (i=a-1;i>=0;i--)
#define DIS(a)includesort(all(a)); a.erase(unique(all(a)),a.end())
#define SI ({int x;scanf("%d",&x);x;})
#define SC ({char c;scanf("%c",&c);c;})
#define SIC ({scanf("%*c");})
#define IATOV(a) ({vector<int> v(a,a+sizeof(a)/sizeof(int));v;})
#define CATOV(a) ({vector<char> v(a,a+sizeof(a)/sizeof(char));v;})
#define LS(a,x) ({int z=(lower_bound(ALL(a),x)-(a).begin());(z==0&&a[0]!=x)?-1:z;})
#define HS(a,x) ({int z=(upper_bound(ALL(a),x)-(a).begin());z;})
#define FILL(a,x) memset(a, x, sizeof(a))
#define SIEVE(a) ({int b=ceil(sqrt(a));VI d(a,0);VI e;int f=2;e.PB(2);e.PB(3);FOR(x,1,b+1){FOR(y,1,b+1){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}FOR(r,5,b+1){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}FOR(c,5,a){if(d[c]){e.PB(c);}}e;})
#define LOG2(X) log(X)/log(2)
#define CASE ({printf("Case #%d: ",testcase+1);})
#define DEBUG 1

// BIT OPERATIONS

#define IFSET(S,X) ((sizeof(S)==4)&&(((S)&(1<<(X)))!=0))||((sizeof(S)==8)&&(((S)&(((int64)(1))<<(X)))!=0))
#define SET(S,X) ((sizeof(S)==4)&&((S)|=(1<<(X))))||((sizeof(S)==8)&&((S)|=(((int64)(1))<<(X))))
#define UNSET(S,X) ((sizeof(S)==4)&&((S)&=(~(1<<(X)))))||((sizeof(S)==8)&&((S)&=(~(((int64)(1))<<(X)))))
#define IS2(X) (X && !(X & (X-1)))
#define SWAPR2L(b,i,j,n) ({unsigned int x=((b>>i)^(b>>j))&((1U<<n)-1);unsigned int r=b^((x<<i)|(x<<j));r;})
#define REVERSEBIT(v) ({unsigned int r=v;int s=sizeof(v)*CHAR_BIT - 1;for(v>>=1;v;v>>=1){r<<=1;r|=v&1;s--}r<<=s;r;})
#define MOD2(x,y) (x&&((1U<<y)-1))
template<class T> inline string DISPLAYBIT(T n,int s,int e) {string a;while(s>=e){if(s<sizeof(n)*CHAR_BIT) IFSET(n,s)?a+='1':a+='0';s--;}return a;}
//#define LOWBIT(n) ((n^(n-1))&n)
//template<class T> inline int COUNTBIT(T n){return (n==0)?0:(1+COUNTBIT(n&(n-1)));}
template<class T> inline int COUNTBIT(T n){return (sizeof(n)==4)?__builtin_popcount(n):__builin_popcountl(n);}
template<class T> inline int LSB(T n){return (sizeof(n)==4)?__builtin_ffs(n)-1:__builtin_ffsl(n)-1;}
template<class T> inline int MSB(T n){return (sizeof(n)==4)?31-__builtin_clz(n):63-__builtin_clzl(n);}
//#define LSB(n) MSB((n^(n-1))&n)
//template<class T> inline unsigned int MSB1(T v){const unsigned int b[]={0x2,0xC,0xF0,0xFF00,0xFFFF0000};const unsigned int S[]={1,2,4,8,16,32};int i;register unsigned int r=0;if(sizeof(v)==8){if(v&0xFFFFFFFF00000000){v>>=S[5];r|=S[5];}}if(v&b[4]){v>>=S[4];r|=S[4];}if(v&b[3]){v>>=S[3];r|=S[3];}if(v&b[2]){v>>=S[2];r|=S[2];}if(v&b[1]){v>>=S[1];r|=S[1];}if(v&b[0]){v>>=S[0];r|=S[0];}return r;}
#define INTERLEAVE(x,y) ({int z; int64 z1;for(int i=0;i<sizeof(x)*CHAR_BIT;i++){z|=(x&1U<<i)<<i|(y&1U<<i)<<(i+1);z1|=(x&1U<<i)<<i|(y&1U<<i)<<(i+1);}(sizeof(x)==4)?z1:z;})
#define NEXT_PERM(a) ({unsigned int t=v|(v-1);unsigned int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));w;})

// NUMBER THEORY FUNCTIONS

template<class T> inline T GCD(T a,T b){if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<class T> inline T LCM(T a,T b){if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<class T> inline T EUCLIDEAN(T a,T b,T &x,T &y){if(a<0){T d=EUCLIDEAN(-a,b,x,y);x=-x;return d;}if(b<0){T d=EUCLIDEAN(a,-b,x,y);y=-y;return d;}if(b==0){x=1;y=0;return a;}else{T d=EUCLIDEAN(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<class T> inline vector<pair<T,int> > FACTORISE(T n){vector<pair<T,int> >R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline vector<pair<int,int> > FACTORIZE(int n){if(n>1e7)return FACTORISE(n);vector<pair<int,int> >R;VI a(SIEVE(n));int i;if(a[LS(a,n)]==n){R.push_back(make_pair(n,1));return R;}int b=(int)sqrt(n);for(i=0;a[i]<=b;i++){if(n%a[i]==0){int d=0;for(;n%a[i]==0;d++,n/=a[i]);R.push_back(make_pair(a[i],d));}}for(;a[i]<n;i++){if(n%a[i]==0){R.push_back(make_pair(a[i],1));break;}}return R;}
template<class T> inline bool IZPRIME(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
template<class T> inline bool ISPRIME(T n){if(n>1e7)return IZPRIME(n);VI a(SIEVE(n));int b=LS(a,n);return (b!=-1&&a[b]==n);}
template<class T> inline T TOTIENT(T n) {vector<pair<T,int> > R=FACTORIZE(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}

//MODULUS OPERATIONS

template<class T> inline T CHECKMOD(T n,T m) {return (n%m+m)%m;}
template<class T> inline T MULTIPLYMOD(T a,T b,T m) {return (T)((((int64)(a)*(int64)(b)%(int64)(m))+(int64)(m))%(int64)(m));}
template<class T> inline T DIVIDEMOD(T a,T b,T m) {T x,y;EUCLIDEAN(b,m,x,y);return MULTIPLYMOD(a,x,m);}
template<class T> inline T POWERMOD(T p,int e,T m) {if(e==0)return 1%m;else if(e%2==0){T t=POWERMOD(p,e/2,m);return MULTIPLYMOD(t,t,m);}else return MULTIPLYMOD(POWERMOD(p,e-1,m),p,m);}

//MATRIX OPERTIONS

template<class T> inline void SHOWMATRIX(vector<vector<T> >& A) {for (int i=0;i<SZ(A);i++){for (int j=0;j<SZ(A[0]);j++)cout<<A[i][j]<<" ";cout<<endl;}}
template<class T> inline void COPYMATRIX(int m,int n,vector<vector<T> >& A,vector<vector<T> >& B) {B.clear();B.resize(n-m+1,vector<T>(n-m+1));for (int i=m,k=0;i<=n;i++,k++){for(int j=m,l=0;j<=n;j++,l++)B[k][l]=A[i][j];}}
template<class T> inline void IDENTITYMATRIX(int n,vector<vector<T> >& A) { A.clear();A.resize(n,vector<T>(n));for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=(i==j)?1:0;}
template<class T,class BinaryOperation> inline void CHECKMATRIX(vector<vector<T> > A,vector<vector<T> > B,vector<vector<T> >& C,BinaryOperation b) {int n=SZ(A);C.clear();C.resize(SZ(A),vector<T>(SZ(A)));for (int i=0;i<SZ(A);i++) for (int j=0;j<SZ(A[0]);j++) C[i][j]=b(A[i][j],B[i][j]);}
template<class T> inline void mulMatrix(vector<vector<T> > A,vector<vector<T> > B,vector<vector<T> >& C) { C.clear();C.resize(SZ(A),vector<T>(SZ(B[0])));for (int i=0;i<SZ(A);i++) for (int j=0;j<SZ(B[0]);j++) for (int k=0;k<SZ(B);k++) C[i][j]+=A[i][k]*B[k][j];}
template<class T> inline void TRANSMATRIX(vector<vector<T> >& B,vector<vector<T> >& A) {B.clear();B.resize(SZ(A[0]),vector<T>(SZ(A)));for(int i=0;i<SZ(B);i++){for(int j=0;j<SZ(B[0]);j++) B[i][j]=A[j][i];}}
template<class T,class BinaryOperation> inline void SCALARMATRIX(vector<vector<T> >& B,vector<vector<T> >& A,T c,BinaryOperation d) {B.clear();B.resize(SZ(A[0]),vector<T>(SZ(A)));for(int i=0;i<SZ(B);i++){for(int j=0;j<SZ(B[0]);j++) B[i][j]=d(A[j][i],c);}}

//TRANSLATOR

template<class T> inline string TOSTRING(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
template<class T> inline void TOVAR(string s,T &r){istringstream sin(s);sin>>r;}
template<class T> inline void STOV(string s,vector<T> &vi){vi.clear();istringstream sin(s);for(T v;sin>>v;vi.push_bakc(v));}
template<class T> inline void VTOS(vector<T> vi,string &s){ostringstream sout;for (int i=0;i<vi.size();i++){if(i>0)sout<<' ';sout<<vi[i];}s=sout.str();}
template<class T> inline vector<T> ATOV(T a[]) {vector<T> v(a,a+sizeof(a)/sizeof(T));return v;}
//template<class T> inline void VTOA(vector<T> a,T &b) {int n=SZ(a);for (int i=0;i<n;i++)b[i]=a[i];}

//FRACTION

template<class T> struct Fraction{T a,b;Fraction(T a=0,T b=1);string toString();};//NOTES:Fraction
template<class T> Fraction<T>::Fraction(T a,T b){T d=GCD(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}
template<class T> string Fraction<T>::toString(){ostringstream sout;sout<<a<<"/"<<b;return sout.str();}
template<class T> Fraction<T> operator+(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b+q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator-(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b-q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator*(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.a,p.b*q.b);}
template<class T> Fraction<T> operator/(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b,p.b*q.a);}

#define LL long long int

#define DEBUG 1

/****************************************************************************************************************************/

int main(){

#ifdef DEBUG
	double tmp_start = clock();
	fprintf(stderr, "Start\n");
#endif

	LL n;
	cin>>n;

	/*
	double a=log((double)n)/log(3.0);
	int b=(int)a;
	LL c=(LL)pow(3,b);
	LL ans=1LL;
	for(int i=b;i>=0;i--){
		LL d=(LL)pow(3,i);
		if(n%d==0)
			break;
		ans=max(ans,n/d+1);
	}
	cout<<ans<<"\n";
	*/

	// above code does the same as below..wondering why it gave wrong ans?

	LL ans=1LL;
	LL a=3;
	while(1){
		if(a>n)
			break;
		if(n%a==0){
			a*=3;
			continue;
		}
		ans=max(ans,n/a+1);
		a*=3;
	}
	cout<<ans<<"\n";

#ifdef DEBUG
	fprintf(stderr, "Total time = %.2lf sec\n", (double)(clock() - tmp_start) / CLOCKS_PER_SEC);
#endif

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (2000006)
#define INF (1LL << 60)
const int MOD = (int)1e9 + 7;

signed main() {
    int n;
    cin >> n;

    int i=3;
    while(1){
        if(n%i==0) {
            i*=3;
            continue;
        }
        cout << n/i+1 << endl;
        return 0;
    }

}

#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
using namespace std;

int n,powaaahhhhhhhh=1;

int32_t main()
{
    cin >> n ;
    while(n%(int)pow(3,powaaahhhhhhhh)==0)powaaahhhhhhhh++;
    int mincoin=(int)pow(3,powaaahhhhhhhh);
    int ans=n/mincoin+(n%mincoin!=0);
    cout << ans << "\n";
    return 0;
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
long long n;
long long  find(long long l){
    if(l%3==0)
        return find(l/3)*3;
    return 1;
}
int main(){
    cin>>n;
    if(n%3!=0){
        long long k=n/3;
        cout<<k+1<<endl;
        return 0;
    }
    else {
        long long k=find(n);
        cout<<n/(k*3)+1;
    }
    return 0;
}

#include<iostream>
#include<Cstdio>
using namespace std;
int main(){
	long long n;
	cin>>n;
	if(n%3!=0){
		cout<<(n+2)/3;
		return 0;
	}
	long long z=1;
	while(n%z==0){
		z*=3;
	}
	cout<<(n+z-1)/z;
}

#include <bits/stdc++.h>
int main(void){
    long long N,now = 1ll;
    std::cin>>N;
    while(now){
        now *= 3;
        if(N%now!=0){
            printf("%lld\r",N/now + 1);
            exit(0);
        }
    }
}

#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<vector>
#define  x first
#define y second
using namespace std;

long long n=1,m,k,l=0,x,y,z,xx,yy;
pair<long long, long long> a[100005];

int main()
{
	//freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	cin>>n;
	if(n==1)
	{
	cout<<1;
	return 0;
	}
	m = 1;
	while(1)
	{
		if(!(n%m))m*=3,++k;
		else break;
	}
	cout<<n/m+1;
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<functional>
#include<cstdlib>
#define ll long long
#define pb push_back()
#define len length()
#define si size()
using namespace std;

ll n,i=1;

int main()
{
	cin>>n;
	while(n%i==0) i*=3;
	cout<<n/i+1;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <map>
#define inf 1e18
#define eps 1e-15
#define MAXN 2000010
#define M 1073741824
using namespace std;

long long n;
int main()
{
    cin>>n;
    long long ans;
    while(n%3==0)
    {
        n/=3;
    }
    if(n==1)ans=1;
    else if(n==2)ans=1;
    else if(n%3!=0)
    {
        ans=n/3+1LL;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
signed main()
{
	scanf("%I64d",&n);
	int ans=0;
	for(int i=3;i;i*=3)
	{
		if(n%i)
		{
			ans+=n/i+1;
			break;
		}
	}
	printf("%I64d",ans);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#define maxx 40
using namespace std;

long long n;
long long a[maxx];

void init()
{
	cin>>n;
	a[0]=1;
	for(int i=1;i<=36;i++)
		a[i]=a[i-1]*3;
}

int main()
{
	init();
	if(n%3)
		cout<<n/3+1;
	else
	{
		int index;
		for(int i=1;i<=36;i++)
			if(n%a[i])
			{
				index=i;
				break;
			}
		cout<<n/a[index]+1;
	}
	return 0;
}

#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <math.h>

using namespace std;

int main()
{
    long long n,ans=0;
    cin>>n;
    while (n%3==0) n=n/3;
    if (n%3==2) ans=n/3; else ans=n/3;
    cout<<ans+1;

}

#include<bits/stdc++.h>
using namespace std;
long long n,k,cur=1;
int main(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(k=0;;k++){
        if(n%cur!=0){
            break;
        }
        else{
            cur*=3;
        }
    }
    cout<<n/cur+1;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n, power = 3;
	cin >> n;
	while (n % power == 0) power *= 3;
	cout << n / power + 1 << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int n;
cin >> n ;
while(n%3==0)
{
    n/=3;
}
cout<<n/3+1;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dop(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long n;
	cin>>n;
	while(n%3==0)
	{
	    n/=3;
	}
	cout<<n/3+1;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define PI 2*asin(1)
#define all(v) v.begin(),v.end()
#define forall(it,v) for(it=v.begin();it!=v.end();it++)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define clr(v,n) memset(v,n,sizeof v)
#define REP(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b) for(int i=a; i<b; i++)
#define sz(v) v.size()
#define pii pair<int,int>
#define pii pair<int,int>
#define F first
#define S second
#define INF INT_MAX
#define INFL 100000000000000007
#define EPS 1e-7
inline ll gcd (ll a, ll b) { return (b?gcd(b, a%b):a); }
inline ll lcm (ll a, ll b) { return (a/gcd(a, b))*b; }
inline int cmp(double x, double y = 0, double tol = EPS){return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;}
using namespace std;
const int MAXN=100005;

ll p[40];

int main(){

	p[0]=3;
	rep(i,1,40) p[i]=3*p[i-1];

	ll n;
	cin >> n;

	REP(i,40){
		if(n%p[i]!=0){
			cout << (ll)ceil(1.0L*n/p[i]) << endl;
			return 0;
		}
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;

int main()
{
    ash;
    ll n;
    cin>>n;
    while(n%3==0){
        n/=3;
    }
    cout<<1+n/3<<"\n";

    return 0;
}

#include <cstdio>
#include <set>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <string>
#include <queue>

using namespace std;

typedef long long LL;

LL n;

LL f(LL n) {
	if(n % 3) return n/3 + 1;
	return f(n/3);
}

int main() {
	scanf("%I64d", &n);
	printf("%I64d\n", f(n));
}

#include <bits/stdc++.h>
using namespace std;

int main(){

    long long n;
    cin>>n;

    long long val = 1;
    while(n%val == 0)   val *= 3;

    long long ans = n/val;
    if(n % val != 0)    ans++;
    cout<<ans;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define LL long long
using namespace std;
LL n,t;
int main()
{
	while(cin>>n){
		t=3;
		while(n%t==0)
			t*=3;
		cout<<n/t+1<<'\n';
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define stop system("pause");
long long arr[100000];
int main()
{
	fast;
	arr[0] = 1;
	int i;
	for (i = 1;; i++)
	{
		arr[i] = arr[i - 1] * 3;
		if (arr[i] > 1e17)break;
	}
	i++;
	long long a;
	cin >> a;
	int ptr = upper_bound(arr, arr + i, a)-arr;
	long long m=0;
	while (ptr >= 0)
	{
		ptr--;
		if (a%arr[ptr+1] == 0)continue;
		m = max(a / arr[ptr+1] + 1, m);
	}
	cout << m << endl;
}

#include <iostream>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    while (n%3==0) n/=3;
    cout<<n/3+1<<endl;
    return 0;
}

#include <iostream>

using namespace std;

typedef long long ll;

int main(){
    ll n;
    cin>>n;
    ll v=1;
    for (ll a=1;a<n;a*=3ll){
        if (n%a>0){
            v=max(v, n/a+1);
        }
    }
    cout<<v<<endl;
}

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"

const int N=100005;

int32_t main()
{
	IOS;
	int n;
	cin>>n;
	vector<int> v;
	int cur=1;
	while(cur<1e18)
	{
		v.push_back(cur);
		cur*=3;
	}
	for(auto it:v)
	{
		if(n%it!=0)
		{
			n/=it;
			n++;
			cout<<n;
			return 0;
		}
	}

 	return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/**
*　　　　　　　　┏┓　　 　┏┓
* 　　　　　　　┏┛┗━━━━━━━┛┗━━━┓
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┃　　　━　　 　┃
* 　　　　　　　┃　＞　　　＜　┃
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┃...　⌒　... 　┃
* 　　　　　　　┃　　　　　　　┃
* 　　　　　　　┗━┓　　　┏━┛
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┃
* 　　　　　　　　　┃　　　┗━━━┓
* 　　　　　　　　　┃　　　　　　　┣┓
* 　　　　　　　　　┃　　　　　　　┏┛
* 　　　　　　　　　┗┓┓┏━┳┓┏┛
* 　　　　　　　　　　┃┫┫　┃┫┫
* 　　　　　　　　　　┗┻┛　┗┻┛
*/
#include<iostream>
#include<cstdio>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<deque>
#include<vector>
#include<bitset>
#include<queue>
#include<string>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<cassert>
#include<functional>
#include<sstream>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))
#define rson(x) ((x<<1)|1)
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int maxn = 2e5 + 5;
vector<ll>t;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifdef DEBUG
	freopen("in.txt", "r", stdin);
	freopen("myout.txt", "w", stdout);
#endif // DEBUG clang++ checker.cpp --target=i686-pc-mingw32 -o checker.exe
	ll i, j, k, m, n;
	t.push_back(1);
	while (*t.rbegin() < 1e17)
	{
		ll tp = *t.rbegin() * 3ll;
		t.push_back(tp);
	}
	cin >> n;
	for (auto it : t)
	{
		if (n%it != 0)
		{
			cout << n / it + 1LL << endl;
			return 0;
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const double PI = 3.141592653589793238463;
int main() {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
//	freopen("out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n;
	cin >> n;
	while (n % 3 == 0) {
		n /= 3;
	}
	cout << n / 3 + 1 << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(long long int i=j;i<k;i++)
int main()
{ios::sync_with_stdio(0);cin.tie(NULL);
long long int n;
cin>>n;
long long int den=1;
while(den<=3*n)
{if(n%den) {long long int p=(n/den)+1;cout<<p;return 0;};
den*=3;
    }
}

#include <stdio.h>
#include <stack>
#include <map>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <climits>
#include <unordered_map>
using namespace std;
#define ll long long
#define mp make_pair
//#define ld long double
const int mod = (1e9) + 7;
const double eps = 1e-6;
const int siz = 1e5 + 5, siz2 = 1e4 + 5;
ll n;
int main()
{
	scanf("%I64d", &n);
	ll v = 1;
	while (v * 3 <= n)
		v *= 3;
	while (n % v != 0)
		v /= 3;
	ll ans = v * 3;
	printf("%I64d\n", n / ans + 1);
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main()
{
    long long int n,arr[37],i,j;
    cin >> n;
    arr[0]=1;
    for(i=1;i<37;i++)
        arr[i]=3*arr[i-1];
    for(i=0;i<37;i++)
        if(arr[i]==n)
        {
            cout << "1";
            exit(0);
        }
    if(n%3!=0)
        cout << n/3 +1;
    else
    {
        for(i=0;i<37;i++)
            if(n<arr[i])
                break;
        if(n%arr[i-1]==0)
        {
            cout << "1";
            exit(1);
        }
        else
        {
            for(j=2;j<i;j++)
                if(n%arr[j]!=0)
                {
                    cout << n/arr[j] +1;
                    break;
                }
        }
    }
    //cout << "Hello world!" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
struct cmp{
	bool operator()(pair<long long,pair<long long,long long>>const&p1,pair<long long,pair<long long,long long>>const&p2)const{
		return p1.first>p2.first;
    	}
    };
#define dsq priority_queue< pair<long long,pair<long long,long long>>,vector< pair<long long,pair<long long,long long>> >,cmp>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define what_is(x) cerr << #x << " is " << x << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vv;
int xd[] = {1,0,-1,0,1,1,-1,-1};
int yd[] = {0,-1,0,1,1,-1,1,-1};
long long lcm(long long a, long long b) { return a * (b / __gcd(a, b)); }
inline bool isEqual(double x, double y){  const double epsilon =  1e-5 ;  return abs(x - y) <= epsilon *abs(x);}
long double triarea(long long x1,long long y1 , long long x2 , long long y2 , long long x3 , long long  y3){return (long double)abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2.0;}
bool triinside(long x1 , long y1 , long x2 , long y2 , long x3 , long y3 , long x , long y){long  area1 = triarea(x1,y1,x2,y2,x3,y3);long  area2 = triarea(x,y,x2,y2,x3,y3);long  area3 = triarea(x1,y1,x,y,x3,y3);long  area4 = triarea(x1,y1,x2,y2,x,y);if(isEqual(area1,area2+area3+area4))return true;return false;}
long long dist(long long x1, long long y1, long long x2, long long y2) {return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);}
const double pi = acos(-1.0);
long double todegree(long double radian){ if(radian<0)radian+=2*pi;return radian*180/pi;}
long double toradian(long double degree){return degree*pi/180.0;}
long long poww(ll x, ll k){ll ret = 1;while (k){if (k & 1) ret = (ret*x);k >>= 1; x = (x*x);}return ret;}
long long sumOfNumbers(long long num){long long ret = 0;	while(num){ret+=num%10;num/=10;}return ret;}
unsigned long long fact(unsigned long long n){unsigned long long sum = 1;while(n>1){sum*=n;n--;}return sum;}
unsigned long long combination(unsigned long long a ,unsigned long long b){long long ret =1;for(int i=0;i<b;i++)ret=ret*(a-i)/(i+1);return ret;}
long double polygon_area(int actual_size, long double x[],long double y[]){long double area = 0.0;for (int i = 0; i < actual_size; ++i){int j = (i + 1)%actual_size; area += 0.5 * (x[i]*y[j] -  x[j]*y[i]);}return (area);}
//void Union( int x, int y){int xset = findpar(par,x);int yset = findpar(par,y);par[xset] = yset;}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int  main()
{
//		freopen("input.txt","r",stdin);
//		freopen("output.txt", "w", stdout);
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	long long num ; cin>>num;
	while(num%3==0)num/=3;
	cout<<num/3+1;
	return 0;
    }

#include <stdio.h>
#include <stack>
#include <map>
#include <string.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <climits>
#include <unordered_map>
#include <iterator>
#include <bitset>
#include <complex>
#include <random>
#include <chrono>
#include <functional>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mp make_pair
#define inf32 INT_MAX
#define inf64 LLONG_MAX
#define PI acos(-1)
#define cos45 cos(PI/4)
#define ld long double
#define inf 1000000
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define pil pair<int, ll>
#pragma GCC optimize ("O3")
//#define x first
//#define y second
const int mod = (1e9) + 7, mod2 = 998244353;
const double eps = 1e-10;
const int siz = 1e6 + 5, siz2 = 19, lg = 31, block = 317, block2 = 1000, mxv = 5e5;

ll n;

int main()
{
	scanf("%I64d", &n);
	ll num = 3;
	while (n%num == 0) {
		num *= 3;
	}
	printf("%I64d\n", n/num + 1);
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define MAX 1000005
typedef long long ll;
const int inf = 2e9;
using namespace std;

ll n;

int main(){
	scanf("%lld",&n);

	ll exponente = double(log(n))/double(log(3));

	ll menor = pow(3,exponente);

	if(menor == n) return !printf("1\n");

	//printf("%lld\n", menor);

	ll k=3;
	for(;n%k==0; k*=3);

	printf("%lld\n", n/k+1);

	return 0;
}

#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
  long long n,i=3;
  cin>>n;
  while(n%i==0)i*=3;
  cout<<(n/i)+1<<endl;

}

#include <iostream>
using namespace std;
#define ll long long

int main() {
	ll n;
	cin >> n;
	while (n % 3 == 0) n /= 3;
	cout << (n / 3) + 1 << endl;
}

										/* in the name of Allah */
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

#define uint unsigned int
#define int64 long long
#define P pair<int, int>
#define Pss pair<string, string>
#define PLL pair<int64, int64>
#define Inf 1000000
#define Mod 1000000007LL

int64 n;
int cnt = 0, p = 0;
int64 arr[100];

int main(){
	cin >> n;
	while(n){
		arr[p++] = n % 3;
		n /= 3;
	}
	int st = 0;
	while(arr[st] == 0)
		st++;
	for(int i = p - 1; i > st + 1; i--)
		arr[i - 1] += arr[i] * 3;
	cout << arr[st + 1] + 1 << endl;
	return 0;
}

//By Nurbergen Hinatolla
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <cstdio>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <cmath>
#include <math.h>
#include <map>
#include <set>
#include <time.h>
#include <bitset>
inline int Rand() { return (rand() << 16) | rand(); }
#define y1 google
#define INF 1000000000000000000LL
#define inf 2147483647
#define MOD 1000000007
#define pf push_front
#define pb push_back
#define mp make_pair
#define FI first
#define SI second
#define fname ""

using namespace std;

typedef long long ll;

const int N = 200005;
const double eps = 1e-9;

int main () {

    #ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
    #endif
    long long n;
    cin >> n;
    if (n < 4)
       cout << 1, exit(0);
    long long mx = 1, i;
    for (i = 1; i <= n; i *= 3) {
        if (n % i == 0)
            continue;
        long long sum = 1 + n / i;
        if (mx < sum)
            mx = sum;
    }
    cout << mx;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin>>n;
	while(!(n%3))n/=3;
	cout<<(n+3)/3<<endl;
	return 0;
}

#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

typedef __int64 ll;

ll n , maxn , ans;
void find_max(){
	maxn = 1;
	while( !( n % maxn ) ) maxn *= 3;
}
int main(){
	scanf( "%I64d" , &n );
	find_max();
	printf( "%I64d\n" , n / maxn + 1 );
}

/*
prakhar3agrwal
Prakhar Agrawal
IIIT Allahabad
*/
#include<iostream>
#include<algorithm>
#include<string.h>
#include<ctype.h>
#include<vector>
#include<math.h>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
int i,y;
string s1,s2;
int main()
{
unsigned long long int n,ans=0,j,k;
cin>>n;
if(n<=3)
{
        cout<<"1\n";
        return 0;
}
j=1;
while(j<n)
j*=3;
if(j==n)
{
        cout<<"1\n";
        return 0;
}
j=1;
while(j<n)
{
          if(n%j!=0)
          break;
          j*=3;
}
k=n%j;
n=n/j;
if(k!=0)
n++;
cout<<n<<"\n";
//system("pause");

}

#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;

ll n,a[37],ans;
int p,pla;

int main() {
	scanf("%I64d",&n);
	a[0]=1;
	  for (int i=1;i<=36;++i) a[i]=a[i-1]*3;
	  for (int i=36;i>=0;--i)
	    if (n%a[i]==0) {
	      p=i+1; break;
	    }
	  for (int i=36;i>=0;--i)
	    if (a[i]>n && a[i-1]<n) {
	      pla=i; break;
	    }
	if ((n/a[p]+1)*a[p]-n<a[pla]-n) ans=n/a[p]+1;
	else if ((n/a[p]+1)*a[p]-n==a[pla]-n) ans=max((ll)1,n/a[p]+1);
	else ans=1;
	printf("%I64d",ans);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;

typedef long long LL;

LL n;

int main()
{
	scanf("%I64d",&n);
	while(n%3==0)
		n/=3;
	cout<<n/3+1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long ans=1,n;
main()
{
	cin>>n;
	while(n%ans==0)ans*=3;
	cout<<((n/ans)+1);
}

#include <cstdio>
int main()
{
	long long n, x=1; scanf("%I64d", &n);
	while(true) {
		if (n%x!=0) {
			printf("%I64d\n", n/x+1);
			return 0;
		}
		x*=3ll;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;
    while (n % 3 == 0) n /= 3;
    cout << (n + 2) / 3 << '\n';

}

#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include<cmath>
#define NM 1
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f cin
#define g cout
using namespace std;
/*
int dx[]={0,1,-1,0,0};
int dy[]={0,0,0,1,-1};
int dx[]={0,0,0,1,1,1,-1,-1,-1};
int dy[]={0,-1,1,-1,0,1,-1,0,1};
*/
long long v[1010],i,lp,nr,nr1,N,T,n;
int main ()
{
    /*freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);*/

    f>>n;
    N=n;
    v[0]=1;
    for(i=1;v[i]<=n;++i)
    {
        v[i]=v[i-1]*3;
        if(v[i]>n)
            break;
    }
    T=i;
    nr=0;
    for(i=T;i>=0;--i)
    {
        while(v[i]<=n)
        {
            n-=v[i];
            lp=v[i];
            nr++;
        }
    }
    n=N;
    lp*=3;
    nr1=n/lp+1;
    g<<nr1;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int nod(int x, int y)
{
    if (x) return nod(y % x,x); else return y;
}

long long nok(long long x, long long y)
{
    return x / nod(x,y) * y;
}

int main()
{
    ios_base :: sync_with_stdio (false);
    cin.tie (NULL);
    long long n,k,ans;
    cin>>n;
    k = 1;
    while(n % k == 0) k *= 3;
    cout<<n/k+1;
}
/*void quickSort(int l, int r)
{
    int x = a[l + (r - l) / 2];

    int i = l;
    int j = r;

    while(i <= j)
    {
        while(a[i] > x) i++;
        while(a[j] < x) j--;
        if(i <= j)
        {
            swap(a[i], a[j]);
            swap(b[i], b[j]);
            i++;
            j--;
        }
    }
    if (i<r)
                quickSort(i, r);

    if (l<j)
        quickSort(l, j);
}*/

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	__int64 n,ans;
	cin>>n;
	while(n%3==0)
	{
		n/=3;
	}
	ans=n/3;
	ans+=1;
	if(n==2)ans=1;
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define PB push_back
#define endl '\n'

typedef long long ll;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

ll mpow(int n) {
    if(n == 0) return 1LL;
    if(n == 1) return 3LL;
    if(n & 1) return 3LL * mpow( n - 1 );
    ll x = mpow(n >> 1);
    return x * x;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n; cin >>  n;
    for(int i=0; i<40; i++) {
        ll m = mpow(i * 1LL);
        if(n % m) {
            cout << (n / m)  + 1 << endl;
            return 0;
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    long long n;
    cin>>n;
    while(n%3==0){
        n/=3;
    }
    cout<<(n/3)+1;
}

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int INF = 2e9+5;

/*
    filippos
    Contest : 334
    Task : C
*/

int main(){
    cin.tie(0), cin.sync_with_stdio(0);
    ull n; cin >> n;
    ull m = 1;
    while(n % m == 0) m *= 3;
    cout << n/m + 1;
}

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long int64;
int64 cal(int64 t)
{
    if(t%3)
    {
      return (t/3+1);
    }
    else
    {
        int64 u=t;
        while(u%3==0)
        {
            u/=3;
        }
       return u/3+1;
      }
}
int main()
{
    int64 t;
    while(cin>>t)
    {
      cout<<cal(t)<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    while(~scanf("%lld",&n))
    {

        if(n%3==0)
        {
            long long int x=1;
            while(x<n)
            {
                x*=3;
                if(n%x!=0)
                {
                    break;
                }
            }
            if(n%x==0)
            {
                printf("1\n");
            }
            else
            {
                printf("%lld\n",n/x+1);
            }
        }
        else
        {
            printf("%lld\n",n/3+1);
        }
    }
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include "math.h"
#include<vector>
#include"string"
#include<algorithm>
#include<map>
#include"queue"
#include"stdlib.h"
#include"stdio.h"
#include<iomanip>
#include<stack>
#include <set>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const ld PI = 3.141592653589793238462643383279502884197169399375105820974944592307816;
struct compare {
    bool operator()(pair<int,int> a,pair<int,int> b) const {
        return abs(a.second)<abs(b.second);
    }
};

int main() {
    ll st = 3, k = 1;
    ll n;
    cin >> n;
    while (n % st == 0) {
        st *= 3;
        k++;
    }
        cout << n / st+1;

}

#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	long long int N, del=3;
	cin>>N;

	for(;;)
	{
		if(N%del!=0)
		{
			cout<<N/del+1<<endl;
			return 0;
		}
		else del=del*3;
	}

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
long long n;
int main()
{
    while(scanf("%I64d",&n) == 1)
    {
        long long temp = 3;
        long long ans = n;
        while(n % temp == 0)
        {
            temp *= 3;
        }
        printf("%I64d\n",n/temp+1);
    }
    return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<stdlib.h>
#include<math.h>
using namespace std;

long long int pow1(long long int a,long long int b)
{
    long long int i,ans=1;
    for(i=0;i<b;i++)
    {
        ans=a*ans;
    }
    return ans;
}

int main()
{
    long long int  n,s,k=0,i,p=0;
    cin>>n;
        for(i=1;i<=38;i++)
        {
            s=pow1(3,i);
            if(n%s!=0)
            {
                p=n/s;
                p++;
                cout<<p;
                return 0;
            }
        }
            cout<<"1";
        return 0;
    return 0;
}

#include <iostream>
#include <cstdio>
#define f cin
#define g cout

using namespace std;

long long N, Val;
int i, M;
int cnt, how;
int V[200];
long long Pow[200];

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
    #endif

    Pow[0]=1;
    for (i=1; i<=36; i++)
        Pow[i]=3LL*Pow[i-1];

    f >> N;

    for (i=0; i<=36; i++)
        if (N%Pow[i]!=0)
        {
            g << N/Pow[i]+1 << '\n';
            return 0;
        }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int             long long
#define gcd(a, b)       __gcd(a, b)
#define here            cout<<"here";
#define lcm(a, b)       ((a)*1ll * (b)) / gcd(a, b)
#define pb              push_back
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define nl              "\n"
#define vi              vector<int>
#define vvi             vector<vector<int> >
#define F               first
#define S               second
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define w(x)            int x; cin>>x; while(x--)
#define fre(i,a,n)      for (int i = a; i <= n; ++i)
#define fr(i,n)         for (int i = 0; i < n; ++i)
#define rf(i,n,a)       for (int i = n; i >=a; --i)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pqi		   priority_queue<int>
#define pqgi            priority_queue<int,vector<int>,greater<int>>
#define MN              min_element
#define MX              max_element
#define all(x)          x.begin(),x.end()
#define YN(ans)         ans ? cout << "YES" : cout << "NO";
#define d0(x)           cout<<(x)<<" "
#define d1(x)           cout<<(x)<<endl
#define d2(x,y)         cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z)       cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d)     cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e)   cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define max3(a,b,c)     max(max((a),(b)),(c))
#define max4(a,b,c,d)   max(max((a),(b)),max((c),(d)))
int pow(int a, int b) {
	int ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a);
		b /= 2;  a = (a * a) ;
	}
	return ans;
}

void start()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

const int N = 200005;
void solve()
{
	int n;cin>>n;
	int temp=n;
	int cnt=0;
	while(temp%3==0) temp/=3,cnt++;
	int num=pow(3,cnt+1);
	int ans=n/num;
	if(n%num) ans++;
	d0(ans);

}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

int32_t main()
{
	FIO;
	start();
	solve();
// w(x)    {solve();}
#ifndef ONLINE_JUDGE
	cerr << "\nTime Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
}

#include<iostream>
using namespace std;
int main(){
	long long n;
	while(cin>>n){
		while (n%3==0) n=n/3;
		long long  t=n/3+1;
		cout<<t<<endl;
	}
}

#include <iostream>

using namespace std;

int main()
{
	long long n, k = 1;
	int ans = 0;
	cin >> n;
	while (n % k == 0)
		k *= 3;
	cout << n / k + 1 << endl;
}

#include<bits/stdc++.h>
#include<string>
#define ll long long
#define llu unsigned long long int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gll(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define mod 1000000007
#define pi 3.1415926535897
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    //std::cout << std::setprecision(9);
    //std::cout << std::fixed;
    ll n,i;
    cin>>n;
    ll a[38],res=1;
    a[0]=1;
    for(i=0;i<=36;i++)
    {
        a[i]=res;
        res*=3;
        //cout<<a[i]<<endl;
    }
    ll x=n,ans=0;
    for(i=0;i<=36;i++)
    {
        if(x%a[i]!=0)
        {
            ans=x/a[i];
            ans++;
            break;
        }
    }
    cout<<ans;
}

#include <bits//stdc++.h>
using namespace std;
typedef long long ll;

ll pow(int p, int n) {
    ll ans = 1;
    for(int i=0; i<n; i++) {
        ans *= p;
    }
    return ans;
}
int main()
{
    ll n, pi;
    cin >> n;

    for(int i=0; ; i++) {
        pi = pow(3, i);

        if(n % pi != 0) break;
    }
    cout << (n+pi-1)/pi << endl;
}

#include <stdio.h>
#include <functional>
#include <bitset>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <string.h>
#include <numeric>
using namespace std;

 typedef vector<int> vi;
 typedef vector<vi> vvi;
 typedef pair<int,int> ii;
 typedef long long ll;
 #define sz(a) int((a).size())
 #define pb push_back
 #define all(c) (c).begin(),(c).end()
 #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
 #define present(c,x) ((c).find(x) != (c).end())
 #define cpresent(c,x) (find(all(c),x) != (c).end())

int main ()
{
	//freopen("*.in","r",stdin);
	//freopen("*.out","w",stdout);

	ll N;
	cin >> N;
	ll ans;

	while (N)
	{
		if (N%3)
		{
			ans = N/3+1;
			break;
		}
		N/=3;
	}

	cout << ans << endl;
}

// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"
#define ret return
#define F first
#define S second

/*##################################################################################*/

/*
int prime[100000] ;
vector < int > pr;
void calculateprime()
{
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; i <= 100000 ; i++)
    {
        if(prime[i] == 0)
        {
            pr.pb(i);
            for(ll j = i*2 ; j <= 100000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/

void customrun(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n)
{
    ll a = 0, b = 1, c, i;
    if( n == 0)
        return a;
    for (i = 2; i <= n; i++)
    {
        c = (a + b);
        a = b;
        b = c;
    }
    return b;
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}

ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

bool comp(const pair < long,long > &a, const pair < long ,long > &b){
    if(a.first == b.first) return a.second < b.second;
    return a.first < b.first;
}

void solve();

int main() {
    clock_t begin = clock();

    fast();
    customrun();
    ll t = 1;
    //cin>>t;
    //calculateprime();
    mfor(i,1,t+1,1)
    {
        //cout<<"Case #"<<i<<": \n";
        solve();
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    //cout<<"\ntime spent is "<<time_spent;
    return 0;
}

bool check(string &str , ll b){
    cout<<"string is "<<str<<el;
    if(str[0] == '0'){ cout<<"edge case \n" ; return false; }

    string bss = to_string(b);
    int i = 0 , bs = bss.size() , n = str.size();

    string cur = str.substr(0,bs);
    ll rem = 0 ;
    while( i < n-bs ){
        ll num = stoll(cur);
        //cout<<"i is "<<i<<el;
        //cout<<"num is "<<num<<el;
        if(num < b) cur += str[i] , ++i;
        else{
            rem = num%b;
            cur = to_string(rem);
        }
    }

    if(rem == 0) return true;
    else return false;
}

void solve(){
    ll n;
    in(n);

    while(n % 3 == 0) n /= 3;

    cout<<(n/3+1);
}

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll __int64
using namespace std ;

const int maxn = 1111111 ;

int main ()
{
    ll n , ans ;
    scanf ( "%I64d" , &n ) ;
    if ( n % 3 ) ans = n / 3 + 1 ;
    else
    {
        ll p = 3 ;
        while ( n % p == 0 ) p *= 3 ;
        ans = n / p + 1 ;
    }
    printf ( "%I64d\n" , ans ) ;
    return 0 ;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;

long long n, c3=1,ans=0;

int main()
{
    cin>>n;
    for(int i=0;i<10000;i++)
    {
        if(n%c3==0) c3*=3;
        else
        {
            cout<<n/c3+1;
            return 0;
        }
    }
    return 0;
}

#include <iostream>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    long long n;
    std::cin >> n;

    long long x = 3;
    long long res = 1;

    while(1) {
        if (n % x != 0) {
            res = n / x + 1;
            break;
        } else {
            x = (x * 3);
        }
    }

    std::cout << res << "\n";
}

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

#define MAX 1000000000
#define MIN INT_MIN
#define FOR(i,a,n) for(int i = a; i < n; ++i)
#define ll long long

int main()
{
	ll n,p = 3;
	cin>>n;

	while(n % p == 0)
		p *= 3;
	cout<<(n / p) + 1<<endl;
	return 0;
}

#include "iostream"
//#include "fstream"
#include "math.h"
#include "string"
#include "vector"
#include "map"
#include "algorithm"
#include "stack"
#include  "set"
#include "stdio.h"
#include "queue"
#include "stdlib.h"
using namespace std;
#pragma comment(linker, "/STACK:67108864")
//#define min(a,b) (a<b)? a: b
//#define max(a,b) (a)

int main()
{
    //ios_base::sync_with_stdio(0);
long long n;
cin>>n;
long long st=1;
long long k=0;
while(n%st==0)
{
st*=3;
k++;
}
long long r=n/st;
r+=(n%st>0);
cout<<r;
        return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>

using namespace std;

int main()
{
    long long a,b,c;
    c=3;
    cin>>a;
    b=a;
    while((a%3)==0){
        a/=3;
    }
    if(b<=3){
        cout<<1<<endl;
        return 0;
    }
    if(a!=1){
        while((b%c)==0){
            c*=3;
        }
        cout<<(b/c)+1<<endl;
        return 0;
    }else{
        cout<<1<<endl;
        return 0;
    }
}

#include<bits/stdc++.h>
#define int long long
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
using namespace std;
signed main()
{
    int n=read();
    while(n%3==0) n/=3;
    printf("%lld\n",(n+2)/3);
    return 0;
}

//#define ONLINE_JUDGE

#if defined(ONLINE_JUDGE)
#define _SECURE_SCL 0
#endif

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <climits>
#include <numeric>
#include <memory.h>

#if !defined(__GNUC__)
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed long int32_t;
typedef unsigned long uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;
#else // !defined(__GNUC__)
#define _CrtDbgBreak()
#endif // !defined(__GNUC__)

#if defined(ONLINE_JUDGE)
#define LOCAL_TEST 0
#else
#define LOCAL_TEST 1
#endif

#if LOCAL_TEST
#define LOCAL_ASSERT(expr) { if (!(expr)) {std::cout << "ASSERT FAILED: '" << #expr << "'" << std::endl; _CrtDbgBreak(); } }
#else
#define LOCAL_ASSERT(expr)
#endif

typedef long double double_t;
typedef std::string string8_t;

typedef std::vector<size_t> vector_size_t;
typedef std::vector<uint64_t> vector_uint64_t;
typedef std::vector<int32_t> vector_int32_t;
typedef std::vector<vector_size_t> vector_2d_size_t;
typedef std::vector<string8_t> vector_string8_t;
typedef std::set<size_t> set_size_t;
typedef std::multiset<string8_t> multiset_string8_t;

// Auxiliary functions definition
//
template<typename T> inline T Abs(const T a) { return a < 0 ? -a : a; }
template<typename T> inline T Min(const T a, const T b) {return a < b ? a : b;}
template<typename T> inline T Max(const T a, const T b) {return a > b ? a : b;}
template<typename T> inline void UpdateMin(T& a, const T b) {a = Min(a, b);}
template<typename T> inline void UpdateMax(T& a, const T b) {a = Max(a, b);}

static const double_t eps = 1.0e-09;
template<typename T> inline bool IsEqual(const T a, const T b) { return Abs(a - b) < eps; }
template<typename T> inline bool IsGreater(const T a, const T b) { return a > b + eps; }
template<typename T> inline bool IsLess(const T a, const T b) { return a + eps < b; }

template<typename T> inline string8_t ToStr(const T& val) { std::ostringstream ostr; ostr << val; return ostr.str(); }
template<typename T> inline bool FromStr(const string8_t& str, T& val) {std::istringstream istr(str); istr >> val; return !!istr; }

#if defined(ONLINE_JUDGE)
template<size_t id> class StopWatch { };
#elif !defined(__GNUC__)
#include <library/lib_stopwatch.h>
#else
#include "../../library/library/lib_stopwatch.h"
#endif

vector_uint64_t PlusOne(const vector_uint64_t& x, const size_t firstIdx)
{
    vector_uint64_t a(x);
    a.push_back(0);

    for (size_t i = 0; i <= firstIdx; i++)
    {
        a[i] = 0;
    }
    uint64_t c = 0;
    a[firstIdx + 1]++;
    for (size_t i = firstIdx + 1; i < a.size(); i++)
    {
        a[i] += c;
        c = 0;
        if (a[i] >= 3)
        {
            c = 1;
            a[i] %= 3;
        }
    }

    return a;
}

bool Solve(std::istream& ist, std::ostream& ost, const bool multipleTestMode)
{
    StopWatch<1> sw; sw;

    //
    uint64_t n;
    ist >> n;

    if (multipleTestMode && !ist)
        return false;

    //
    uint64_t t = n;
    vector_uint64_t x;
    while (t > 0)
    {
        x.push_back(t % 3);
        t /= 3;
    }

    uint64_t sMax = 1;
//  for (size_t i = 0; i < x.size(); i++)
//  {
//      if (x[i] != 0)
//      {
//          const vector_uint64_t added = PlusOne(x, i);
//          const uint64_t s = std::accumulate(added.begin(), added.end(), 0ULL);
//          sMax = Max(s, sMax);
//      }
//  }
    uint64_t v = 3;
    for (size_t p = 1; p <= x.size(); p++)
    {
        if (n % v != 0)
        {
            const uint64_t s = (n + v - 1) / v;
            UpdateMax(sMax, s);
        }
        v *= 3;
    }
    ost << sMax << std::endl;

    return multipleTestMode;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::istream& ist = std::cin;
    std::ostream& ost = std::cout;
#if defined(ONLINE_JUDGE)
    Solve(ist, ost, false);
#else
    while(Solve(ist, ost, true)) {};
#endif
}

#include<cstdio>
int main(){

        long long n;
        long long ret=1;
        scanf("%I64d",&n);
        if(n>=1 && n<=3)
            printf("1\n");
        else if(n%3)
            printf("%I64d\n",(n/3)+1);

         else{
              for(long long  i=3;i<=n;i*=3)
                 if(n%i){
                         ret=(n/i)+1;
                         break;
                  }
              printf("%I64d\n",ret);
       }

}

#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll ;

const int MAXN = 2001 ;

ll n ;

int main(){
    cin >> n ;
    ll mod = 1LL ;
    while (n % mod==0) mod = mod * 3 ;
    cout << (n + mod - 1) / mod << endl ;
    return 0 ;
}

/*
ID: wengsht1
LANG: C++
TASK: test
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <sstream>
#include <set>
using namespace std;

#define MX 100005
#define REP(i,n) for(int i=0;i<(n);i++)
#define OREP(i,n) for(int i=1;i<=(n);i++)

typedef long long          LL;
typedef unsigned long long ULL;
typedef unsigned int       UINT;

unsigned long long n, m, k, t;

unsigned long long f[MX];
int main() {
    cin >> n;

    f[0] = 1;
    OREP(i, 20) f[i] = f[i-1] * 3LL;

    while(n % 3 == 0) n /= 3;
    cout << n / 3 + 1 << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
main()
{
	ll n;
	cin>>n;
	double x=log(n)/log(3);
	if(x==(int)x)
		cout<<1;
	else
	{
		ll y=1;
		while(y<=n)
		{
			if(n%y!=0)
			 break;
			y=y*3;
		}
			cout<<(n/y)+1;

	}
}

#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include <deque>
#include <list>
using namespace std;

#define ll long long
#define db double
#define pi acos(-1)
#define pb push_back

#define pf printf
#define sf scanf
#define sof sizeof
#define pob pop_back()
#define gcd(a,b) __gcd(a,b)
#define logab(a,b) (log(a) / lob(b))
#define mem(a,v) memset(a, v, sizeof(a))
#define m_p make_pair
#define all(v) (v.begin(), v.end())
#define loop(type, v, it) for(type::iterator it = v.begin(); it != v.end(); ++it)
#define rep(i, a, n) for(int i = a; i <= n; ++i)
#define rrep(i, a, n) for(int i = n; i>= 0; i--)

#define sf1(a) scanf("%d", &a)
#define sf2(a, b) scanf("%d %d", &a, &b)
#define sf3(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define sf4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d);

#define sfl1(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld%lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sfl4(a,b,c,d) scanf("%lld%lld%lld%lld",&a,&b,&c,&d)

#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pf3(a,b,c) printf("%d %d %d\n",a,b,c)
#define pf4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)

#define pfl1(a) printf("%lld\n",a)
#define pfl2(a,b) printf("%lld %lld\n",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define pfl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)

#define lb lower_bound
#define ub upper_bound
#define fr first
#define sc second
#define exp1 exp(1)

int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
//k=unique(mas,mas+k)-mas;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;

int cas = 1;
int dxx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dyy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};

#define M 100006
#define mod 1000000007
/*
bool mark[M];
ll prime[M];
void seive()
{
    prime[0] = 2;
    int c = 1;
    for(int i = 3; i*i <= M; i+= 2)
    {
        if(mark[i] == false)
        {
            for(int j = i*i; j < M; j+= i+i)
                mark[j] = true;
        }
    }
    for(int i = 3; i <= M; i+= 2)
    {
        if(mark[i] == false)
        {
            prime[c++] = i;
        }
    }
}*/

int main()
{
    //freopen("input.txt","r",stdin);
     //freopen("output.txt","w",stdout);
    ll n,s,j,k;

    sfl1(n);
    s=0;
    ll i=0;
    while(n>0)
    {
       i++;
       j=1;
       for(k=0;k<i;k++)j*=3;
       if(n%j!=0)break;
    }
    s=n/j;
    s++;
    pfl1(s);

}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <utility>
typedef long long LLD;
using namespace std;
int main()
{
    LLD n;
    cin >> n;
    LLD p = 1;
    while(n%p == 0)
	p *= 3;
    LLD ans = n/p + 1;
    cout << ans << endl;
    return 0;
}

 #include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int p=1;p<=t;p++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
ll power(ll a,ll b){ ll ans=1;    while(b>0){ if(b&1){ ans=ans*a;} a=a*a; b=b/2; } return ans; }
int main(){
   ll n,t;
   cin>>n;
   ll arr[50];
   ll ans=0;
   ll k=0;
   memset(arr,0,sizeof(arr));
   ll a=3;
   while(n>0){

       arr[k]=n%a;
       n=n/a;

       k++;

   }
   int flag=1;
   ll num;

   for(ll i=0;i<50;i++){
       if(arr[i]){
           if(flag){
           flag=0;
            num=power(3,i+1);

           ans++;
           }else{

               ll temp=power(3,i);

               temp=temp/num;

               temp*=arr[i];
               ans+=temp;
           }
       }

   }
   cout<<ans<<endl;

}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
long long n;
long long  find(long long l){
    if(l%3==0)
        return find(l/3)*3;
    return 1;
}
int main(){
    cin>>n;
    if(n%3!=0){
        long long k=n/3;
        cout<<k+1<<endl;
        return 0;
    }
    else {
        long long k=find(n);
        cout<<n/(k*3)+1;
    }
    return 0;
}

#include <stdio.h>
#include <string.h>

int tem[20];

int main(){
    long long i,res;
    long long n;
    scanf("%I64d",&n);
    while(n%3==0)n/=3;
    n/=3;n++;
    printf("%I64d\n",n);
    return 0;
}

#include<stdio.h>
int main(){
long long t,num,r=1;
scanf("%I64d",&num);
while(num!=0){
   if(num%r!=0){
      break;
   }
   else r*=3;
}
t=num/r+1;
printf("%I64d",t);
}

#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
	cin>>n;
	while(n%3==0)n/=3;
	cout<<n/3+1;
}

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
using namespace std;
typedef __int64 ll;
ll  n;
ll quick(ll m,ll n)
{
    ll b = 1;
    while (n > 0)
    {
          if (n & 1)
             b = (b*m);
          n = n >> 1 ;
          m = (m*m);
    }
    return b;
}

int main()
{
    cin>>n;
    ll a ;ll b;

    for (ll i=0;;i++)
    {     a=quick(3,i);

          if(n==a)
          {
              cout<<1<<endl;
              return 0;
          }
       if(n%a!=0)
       {
            cout<<(n/a)+1<<endl;
            return 0;
       }

    }

}

#include<bits/stdc++.h>
using namespace std;
int main() {
	long long a;
	cin>>a;
	while(a%3==0){
		a/=3;
	}
	cout<<a/3+1;
}

#include <bits/stdc++.h>

#define int long long
#define mp make_pair
#define pb push_back
#define min3(a,b,c) min(min(a,b),c)
#define max3(a,b,c) max(max(a,b),c)
#define EPS 0.00000001

const int inf = 4e18; ///
const int mod2 = 1e9+7;

using namespace std;
void print(vector<int> & v){
    for(auto it:v) cout << it << " ";
    cout << "\n";
}
signed main(){
    int n;
    cin >> n;
    while(n%3 == 0) n/=3;
    cout << n/3+1;
}

/*
 * File:      main.cpp
 * Author:    Hrayr [HarHro94]
 * Problem:
 * IDE:       Visual C++ 2012
 */
//#pragma comment(linker, "/STACK:67108864")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef long double LD;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

const int N = 100007;

int main()
{
#ifdef harhro94
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    LL n;
    cin >> n;
    LL pw = 1;
    while (n % pw == 0)
    {
        pw *= 3;
    }
    cout << (n + pw - 1) / pw << endl;

#ifdef harhro94
    cerr << fixed << setprecision(3) << "\nExecution time = " << clock() / 1000.0 << "s\n";
#endif
    return 0;
}

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef double ld;
const int NMax=1001000;
LL N;
int main()
{
	scanf("%I64d",&N);
	LL nn=N;
	int cnt=0;
	while(nn>0&&nn%3==0){
		nn/=3;
	}
	printf("%I64d",nn/3+1);
	getchar();getchar();
	return 0;
}

//          * AUTHOR : Divyanshu *

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define f(a,b) for(ll i=a; i<b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define pll vector<pair<ll,ll>>
#define ld long double
#define fr(a,b) for(ll j=a; j>=b; j--)
#define fi(a,b) for(ll j=a; j<b; j++)
#define fii(a,b) for(ll k=a; k<b; k++)

int main()
{
    #ifndef ONLINE_JUDGE
	   freopen("input.txt", "rt", stdin);
   	// freopen("output.txt", "wt", stdout); *No Need*
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);

    ll n, ans=1;
    cin>>n;
    ll a[40] = {0};
    a[0]=1;
    f(1, 41)
        a[i] = a[i-1]*3;
    f(1, 41)
    {
        if(n%a[i])
        {
            ans = n/a[i];
            ans++;
            break;
        }
    }
    cout<<ans;

     #ifndef ONLINE_JUDGE
    	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
    #endif
}

#include<cstdio>
int main(){

	long long n;
	scanf("%I64d",&n);

			printf("%I64d\n",(n/3)+1);

}

#include <iostream>
using namespace std;
int main(){
	long long n, p = 3; cin >> n;
	while(p*3 < n){
		p*=3;
	}
	cout << n / p + 1;
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
using namespace std;

int ans,a[105],b,i,j;
long long n;

int main()
{
	scanf("%I64d",&n);
	for(;n;n/=3)a[++b]=n%3;
	for(i=b;i>=1;--i){ans+=a[i];if(a[i]!=2)break;}
	for(j=1;j<=b;++j)if(a[j])break;
	if(i<=j)printf("1\n");
	else printf("%d\n",ans+1);
}

#include <iostream>
using namespace std;

 int main ()
{
    long long n;
    float k=1;

    cin >> n;

    while (n% (int)(pow (3, k))==0)
        k++;

    cout<< (long long)floor (n/ pow (3, k))+1;

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<pii> vp;

const double PI = 3.141592653589793238;

template<typename T>
std::ostream& operator << (std::ostream& os, const std::vector<T>& vector) {
  for (size_t i = 0; i < vector.size(); ++i) {
    os << vector[i] << " ";
  }
  return os;
}

ll n;

int three_power[38];

void Set() {
  three_power[0] = 1;
  for (int i = 1; i <= 37; ++i) {
    three_power[i] = three_power[i - 1] * 3;
  }
}

bool Search(ll n) {
  forn(i, 38) {
    if (three_power[i] == n) {
      return true;
    }
  }
  return false;
}

ll Go() {
  ll r = 1;
  for (int i = 1; i < 38; ++i) {
    if (n % three_power[i] != 0) {
      r = three_power[i];
      break;
    }
  }
  return n / r + 1;
}

/*
ll Go() {
  if (n % 3 == 0) {
    if (n % 9 == 0) {
      int r = 0;
      for (int i = 3; i < 38; ++i) {
        if (n % three_power[i] != 0) {
          r = three_power[i];
          break;
        }
      }

      return n / r + 1;

    } else {
      return n / 9 + 1;
    }
  }
  return n / 3 + 1;
}
*/

int main() {
  std::ios_base::sync_with_stdio(false);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  Set();

  cin >> n;
  cout << Go() << "\n";
  return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

//ifstream F("in.in");
//ofstream G("out.out");

#define F cin
#define G cout

typedef long long i64;

i64 N;

int main()
{
    F>>N;
    int co = 0;
    i64 i = 3;
    while ( N % i == 0 )
        i *= 3;
    co = N / i;
    if ( N % i != 0 ) ++co;
    G<<co<<'\n';
}

/*
 *  Author: Tara Prasad
 */
#include <bits/stdc++.h>
// #include "printcpp11.h"
using namespace std;

#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define REV_ALL(x) x.rbegin(), x.rend()
#define SZ(x) (int)x.size()
#define CONTAINS(cont, val) (cont.find(val) != cont.end())
#define endl '\n'
#define IO_SPEED_UP ios::sync_with_stdio(false);cin.tie(NULL)
#define FOR(i, s, e) for(ll i = s; i < e; i++)
#define leftmost_set(x) __builtin_clzll(x)
#define CASET int ___T; cin >> ___T; while (___T--)
#define wi(x) what_is(x)
#define what_is(x) cerr << #x << " = " << x << endl;
#define PARENT(n) (n / 2)
#define LCHILD(n) (2 * n)
#define RCHILD(n) (2 * n + 1)

typedef long long ll;typedef pair<ll, ll> ii;
typedef vector<ll> vi;typedef vector<bool> vb;
typedef vector<ii> vii;typedef vector<vi> vvi;

const ll PINF = 1E9;
const ll NINF = -1E9;
const ll M = 1E9 + 7;
const double EPS = 1E-9;
const double PI = 2 * acos(0);

template <typename T> ostream& operator<<(ostream& os, const vector<T> &p){os << "[ "; for (T x: p) os << x << " "; os << "]" << endl; return os;}
template <typename T> ostream& operator<<(ostream& os, const set<T> &p){os << "{ "; for (T x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const map<Tk, Tv> &p){os << "{ "; for (pair<Tk, Tv> x: p) os << x << " "; os << "}" << endl; return os;}
template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv> &p){os << "{" << p.first << ',' << p.second << "}";return os;}

void get_arr(vi& a, int n) {
	if(SZ(a) < n) a.resize(n); for(int i = 0; i < n; i++) cin >> a[i];
}

void print_arr(const vi &a) {
	for(int i = 0; i < SZ(a); i++) {cout << a[i] << " ";} cout << endl;
}

int main() {
	IO_SPEED_UP;
	if(fopen("tupni.txt", "r")) {
		freopen("tupni.txt", "r", stdin);
		freopen("tuptuo.txt", "w", stdout);
	}
	ll n; cin >> n;
	int MAX_POWER = log(1E18)/log(3); // 37
	ll pows = 1;
	if(n == pows) {
		return 0 * puts("1");
	}
	for (int i = 1; i <= MAX_POWER; ++i) {
		pows = pows * 3;
		if(pows == n) { // any 3^k we choose as the first element will be
			// divide n, so to give the minimum coins, give n directly
			cout << 1 << endl; // exact change
			break;
		} else if(pows < n) {
			if(n % pows != 0) {
				ll ans = n/pows + 1;
				cout << ans << endl;
				break;
			}
		}
	}

}

#include <iostream>

using namespace std;

int main()
{
    long long a3 [36];
    a3[0] = 1;
    for (int i = 1; i < 36; i++)
        a3[i] = a3[i-1] *  3;
    long long n;
    cin >> n;
    if ( n % 3  == 0 ){
        int j = 1;
        while ( true ){
            if ( n % a3[j] == 0  ){
                j++;
                continue;
            }
            else{
                cout << n / a3[j] + 1;
                return 0;
            }
            if ( j == 36 ) break;
        }
        return 0;
    }
    cout << n /3 + ( n % 3 == 2 ? 1 : 1  );
    return 0;
}

#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
	long long n=0;
	scanf("%I64d",&n);
	long long ans=3;
	for(;n%3==0;n/=3)ans*=3ll;
	printf("%I64d\n",n/ans+1);
	return 0;
}

#include <vector>
#include <list>
#include <map>
#include <math.h>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <string.h>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <unordered_map>

using namespace std;

#define ll  long long int
#define ld long double

ll LOG(ll number)
{
	ll ret = 1;
	while (number < ret && number%ret)ret *= 3;

	return ret;
}
int main()
{
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll n, x;
	while (cin >> n)
	{
		x = LOG(n);
		cout << max(1ll, n / x + 1) << endl;
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace std;

int n;
int  p[22];

int main()

{

	scanf("%d",&n);
	p[0] = 1;
	for ( int i = 1; i <= 17; i++ )
		p[i] = p[i-1]  * 3;

	int j = 1;
	for ( j = 1; j <= 20; j++ )
		if ( n % p[j] != 0 ) break;

	printf("%d", (n + p[j] - 1) / p[j]);

}

#include <iostream>
#include <vector>
#include <map>

using namespace std;
#define In std::cin
#define Out std::cout

typedef long double LD;

int main(void) {
	LD curVal, tmp = 1;
	int pow3 = 0;

	In >> curVal;

	while (1) {
		tmp *= 3;
		pow3++;
		if (tmp >= curVal)
			break;
	}

	long long res = tmp == curVal ? 1 : ceil(curVal / 3);

	Out << res;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define endl '\n'

ll pow_mod(ll a, ll e) {
  ll ret = 1LL;
  while (e > 0) {
    if (e & 1) ret *= a;
    a *= a;
    e >>= 1;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);

  ll n;
  cin >> n;

  ll ans = 0;
  for (int exp = 33; exp >= 0 && n >= 0; --exp) {
    ll x = pow_mod(3, exp);
    ll cur = n / x;
    ans += cur;
    n -= cur*x;
    // if (n%x == (x-1)) {
    //   n -= x;
    //   ++ans;
    // }
  }

  // if (n > 0) ++ans;
  cout << ans << endl;

}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <set>
#include <map>

using namespace std;

int i,j;
//long long  a[211111],b[211111],nom[211111];
int m,t,n,k,l,r,tp,z,ans,tt;
long long s[60],a[66];

int main() {
  // freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
long long t,ans=0;

cin>>t;
s[1]=1;
for (i=2;i<40;i++) s[i]=s[i-1]*3;

for (i=39;i;i--)
 { a[i]=t/s[i];
 //ans+=a[i];
 t=t%s[i];
     }
//for (i=0;i<40;i++) cout<<a[i];
 i=1;
 while (a[i]==0) i++;
if (a[i]==2) a[i]=0; else a[i]--;
a[++i]++;
// while (a[i]==3)
// {a[i]=0;a[++i]++;}

//for (i=0;i<40;i++) cout<<a[i];

 for (i=1;i<40;i++)
  ans+=a[i];
     cout<<ans;

}

/************************************************************************************************************

	AUTHOR : coderhead_42

	FILE NAME : secrets.cpp

	CREATION DATE : Sat 27 Jul 2013 02:17:14 PM IST

	LAST MODIFIED : Sat 27 Jul 2013 02:21:41 PM IST

*************************************************************************************************************/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>

using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<vector <int> > VVI;
typedef vector<vector <int> >::iterator VVII;
typedef vector<string> VSTR;
typedef vector<string>::iterator VSTRI;
typedef string STR;
typedef string::iterator STRI;
typedef pair<int,int> PII;
typedef list<int> LI;
typedef list<int>::iterator LII;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;

#define INF (int)1e9
#define LINF (long long)1e18
#define EPS 1e-9
#define PI 3.1415926
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int) (x).size())
#define LEN(X) ((int)(X.length()))
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORi(i,a,b) for (i=a;i<b;i++)
#define ROF(i,a,b) for(int i=a-1;i>=b;i--)
#define ROFi(i,a,b) for (i=a-1;i>=0;i--)
#define DIS(a)includesort(all(a)); a.erase(unique(all(a)),a.end())
#define SI ({int x;scanf("%d",&x);x;})
#define SC ({char c;scanf("%c",&c);c;})
#define SIC ({scanf("%*c");})
#define IATOV(a) ({vector<int> v(a,a+sizeof(a)/sizeof(int));v;})
#define CATOV(a) ({vector<char> v(a,a+sizeof(a)/sizeof(char));v;})
#define LS(a,x) ({int z=(lower_bound(ALL(a),x)-(a).begin());(z==0&&a[0]!=x)?-1:z;})
#define HS(a,x) ({int z=(upper_bound(ALL(a),x)-(a).begin());z;})
#define FILL(a,x) memset(a, x, sizeof(a))
#define SIEVE(a) ({int b=ceil(sqrt(a));VI d(a,0);VI e;int f=2;e.PB(2);e.PB(3);FOR(x,1,b+1){FOR(y,1,b+1){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}FOR(r,5,b+1){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}FOR(c,5,a){if(d[c]){e.PB(c);}}e;})
#define LOG2(X) log(X)/log(2)
#define CASE ({printf("Case #%d: ",testcase+1);})
#define DEBUG 1

// BIT OPERATIONS

#define IFSET(S,X) ((sizeof(S)==4)&&(((S)&(1<<(X)))!=0))||((sizeof(S)==8)&&(((S)&(((int64)(1))<<(X)))!=0))
#define SET(S,X) ((sizeof(S)==4)&&((S)|=(1<<(X))))||((sizeof(S)==8)&&((S)|=(((int64)(1))<<(X))))
#define UNSET(S,X) ((sizeof(S)==4)&&((S)&=(~(1<<(X)))))||((sizeof(S)==8)&&((S)&=(~(((int64)(1))<<(X)))))
#define IS2(X) (X && !(X & (X-1)))
#define SWAPR2L(b,i,j,n) ({unsigned int x=((b>>i)^(b>>j))&((1U<<n)-1);unsigned int r=b^((x<<i)|(x<<j));r;})
#define REVERSEBIT(v) ({unsigned int r=v;int s=sizeof(v)*CHAR_BIT - 1;for(v>>=1;v;v>>=1){r<<=1;r|=v&1;s--}r<<=s;r;})
#define MOD2(x,y) (x&&((1U<<y)-1))
template<class T> inline string DISPLAYBIT(T n,int s,int e) {string a;while(s>=e){if(s<sizeof(n)*CHAR_BIT) IFSET(n,s)?a+='1':a+='0';s--;}return a;}
//#define LOWBIT(n) ((n^(n-1))&n)
//template<class T> inline int COUNTBIT(T n){return (n==0)?0:(1+COUNTBIT(n&(n-1)));}
template<class T> inline int COUNTBIT(T n){return (sizeof(n)==4)?__builtin_popcount(n):__builin_popcountl(n);}
template<class T> inline int LSB(T n){return (sizeof(n)==4)?__builtin_ffs(n)-1:__builtin_ffsl(n)-1;}
template<class T> inline int MSB(T n){return (sizeof(n)==4)?31-__builtin_clz(n):63-__builtin_clzl(n);}
//#define LSB(n) MSB((n^(n-1))&n)
//template<class T> inline unsigned int MSB1(T v){const unsigned int b[]={0x2,0xC,0xF0,0xFF00,0xFFFF0000};const unsigned int S[]={1,2,4,8,16,32};int i;register unsigned int r=0;if(sizeof(v)==8){if(v&0xFFFFFFFF00000000){v>>=S[5];r|=S[5];}}if(v&b[4]){v>>=S[4];r|=S[4];}if(v&b[3]){v>>=S[3];r|=S[3];}if(v&b[2]){v>>=S[2];r|=S[2];}if(v&b[1]){v>>=S[1];r|=S[1];}if(v&b[0]){v>>=S[0];r|=S[0];}return r;}
#define INTERLEAVE(x,y) ({int z; int64 z1;for(int i=0;i<sizeof(x)*CHAR_BIT;i++){z|=(x&1U<<i)<<i|(y&1U<<i)<<(i+1);z1|=(x&1U<<i)<<i|(y&1U<<i)<<(i+1);}(sizeof(x)==4)?z1:z;})
#define NEXT_PERM(a) ({unsigned int t=v|(v-1);unsigned int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));w;})

// NUMBER THEORY FUNCTIONS

template<class T> inline T GCD(T a,T b){if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<class T> inline T LCM(T a,T b){if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<class T> inline T EUCLIDEAN(T a,T b,T &x,T &y){if(a<0){T d=EUCLIDEAN(-a,b,x,y);x=-x;return d;}if(b<0){T d=EUCLIDEAN(a,-b,x,y);y=-y;return d;}if(b==0){x=1;y=0;return a;}else{T d=EUCLIDEAN(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<class T> inline vector<pair<T,int> > FACTORISE(T n){vector<pair<T,int> >R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline vector<pair<int,int> > FACTORIZE(int n){if(n>1e7)return FACTORISE(n);vector<pair<int,int> >R;VI a(SIEVE(n));int i;if(a[LS(a,n)]==n){R.push_back(make_pair(n,1));return R;}int b=(int)sqrt(n);for(i=0;a[i]<=b;i++){if(n%a[i]==0){int d=0;for(;n%a[i]==0;d++,n/=a[i]);R.push_back(make_pair(a[i],d));}}for(;a[i]<n;i++){if(n%a[i]==0){R.push_back(make_pair(a[i],1));break;}}return R;}
template<class T> inline bool IZPRIME(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
template<class T> inline bool ISPRIME(T n){if(n>1e7)return IZPRIME(n);VI a(SIEVE(n));int b=LS(a,n);return (b!=-1&&a[b]==n);}
template<class T> inline T TOTIENT(T n) {vector<pair<T,int> > R=FACTORIZE(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}

//MODULUS OPERATIONS

template<class T> inline T CHECKMOD(T n,T m) {return (n%m+m)%m;}
template<class T> inline T MULTIPLYMOD(T a,T b,T m) {return (T)((((int64)(a)*(int64)(b)%(int64)(m))+(int64)(m))%(int64)(m));}
template<class T> inline T DIVIDEMOD(T a,T b,T m) {T x,y;EUCLIDEAN(b,m,x,y);return MULTIPLYMOD(a,x,m);}
template<class T> inline T POWERMOD(T p,int e,T m) {if(e==0)return 1%m;else if(e%2==0){T t=POWERMOD(p,e/2,m);return MULTIPLYMOD(t,t,m);}else return MULTIPLYMOD(POWERMOD(p,e-1,m),p,m);}

//MATRIX OPERTIONS

template<class T> inline void SHOWMATRIX(vector<vector<T> >& A) {for (int i=0;i<SZ(A);i++){for (int j=0;j<SZ(A[0]);j++)cout<<A[i][j]<<" ";cout<<endl;}}
template<class T> inline void COPYMATRIX(int m,int n,vector<vector<T> >& A,vector<vector<T> >& B) {B.clear();B.resize(n-m+1,vector<T>(n-m+1));for (int i=m,k=0;i<=n;i++,k++){for(int j=m,l=0;j<=n;j++,l++)B[k][l]=A[i][j];}}
template<class T> inline void IDENTITYMATRIX(int n,vector<vector<T> >& A) { A.clear();A.resize(n,vector<T>(n));for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=(i==j)?1:0;}
template<class T,class BinaryOperation> inline void CHECKMATRIX(vector<vector<T> > A,vector<vector<T> > B,vector<vector<T> >& C,BinaryOperation b) {int n=SZ(A);C.clear();C.resize(SZ(A),vector<T>(SZ(A)));for (int i=0;i<SZ(A);i++) for (int j=0;j<SZ(A[0]);j++) C[i][j]=b(A[i][j],B[i][j]);}
template<class T> inline void mulMatrix(vector<vector<T> > A,vector<vector<T> > B,vector<vector<T> >& C) { C.clear();C.resize(SZ(A),vector<T>(SZ(B[0])));for (int i=0;i<SZ(A);i++) for (int j=0;j<SZ(B[0]);j++) for (int k=0;k<SZ(B);k++) C[i][j]+=A[i][k]*B[k][j];}
template<class T> inline void TRANSMATRIX(vector<vector<T> >& B,vector<vector<T> >& A) {B.clear();B.resize(SZ(A[0]),vector<T>(SZ(A)));for(int i=0;i<SZ(B);i++){for(int j=0;j<SZ(B[0]);j++) B[i][j]=A[j][i];}}
template<class T,class BinaryOperation> inline void SCALARMATRIX(vector<vector<T> >& B,vector<vector<T> >& A,T c,BinaryOperation d) {B.clear();B.resize(SZ(A[0]),vector<T>(SZ(A)));for(int i=0;i<SZ(B);i++){for(int j=0;j<SZ(B[0]);j++) B[i][j]=d(A[j][i],c);}}

//TRANSLATOR

template<class T> inline string TOSTRING(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
template<class T> inline void TOVAR(string s,T &r){istringstream sin(s);sin>>r;}
template<class T> inline void STOV(string s,vector<T> &vi){vi.clear();istringstream sin(s);for(T v;sin>>v;vi.push_bakc(v));}
template<class T> inline void VTOS(vector<T> vi,string &s){ostringstream sout;for (int i=0;i<vi.size();i++){if(i>0)sout<<' ';sout<<vi[i];}s=sout.str();}
template<class T> inline vector<T> ATOV(T a[]) {vector<T> v(a,a+sizeof(a)/sizeof(T));return v;}
//template<class T> inline void VTOA(vector<T> a,T &b) {int n=SZ(a);for (int i=0;i<n;i++)b[i]=a[i];}

//FRACTION

template<class T> struct Fraction{T a,b;Fraction(T a=0,T b=1);string toString();};//NOTES:Fraction
template<class T> Fraction<T>::Fraction(T a,T b){T d=GCD(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}
template<class T> string Fraction<T>::toString(){ostringstream sout;sout<<a<<"/"<<b;return sout.str();}
template<class T> Fraction<T> operator+(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b+q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator-(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b-q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator*(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.a,p.b*q.b);}
template<class T> Fraction<T> operator/(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b,p.b*q.a);}

#define LL long long int

#define DEBUG 1

/****************************************************************************************************************************/

int main(){

#ifdef DEBUG
	double tmp_start = clock();
	fprintf(stderr, "Start\n");
#endif

	LL n;
	cin>>n;

	double m=(double)(((LL)2*n)+1LL);
	double p=log(m);
	double q=log(3);
	double r=p/q;
	LL ans=(LL)ceil(r);
	cout<<ans<<"\n";

#ifdef DEBUG
	fprintf(stderr, "Total time = %.2lf sec\n", (double)(clock() - tmp_start) / CLOCKS_PER_SEC);
#endif

	return 0;
}

#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;

#ifndef ONLINE_JUDGE
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
	template<class S,class T>
	ostream &operator <<(ostream& out,const pair<S,T>& a){
		out<<'('<<a.fr<<','<<a.sc<<')';
		return out;
	}
}

lint readL(){
	lint res;
#ifdef ONLINE_JUDGE
	scanf("%I64d",&res);
#else
	scanf("%lld",&res);
#endif
	return res;
}
void printL(lint res){
#ifdef ONLINE_JUDGE
	printf("%I64d",res);
#else
	printf("%lld",res);
#endif
}

//const int INF=5e8;

lint n;
int main(){
	while(cin>>n){
	string s;
	while(n){
		s+=n%3+'0';
		n/=3;
	}
	s+='0';
	reverse(ALL(s));

	int res=0;
	int ever=0;
	REP(i,s.size()-1){
		if(s[i]!='2'){
			int zero=1;
			REPN(j,s.size(),i+1) if(s[j]!='0') zero=0;

			if(!zero) chmax(res,ever+s[i]-'0'+1);
		}
		ever+=s[i]-'0';
	}
	cout<<res<<endl;
	}

	return 0;
}

#include<iostream>

using namespace std ;

int main(){
    long long n ;
    cin >> n ;
    for(int i = 1 ; i <= 1e17 ; i = i*3){
        if(n == 1) {cout << "1" ;
         return 0 ;}
        if (n % i) {
            cout << n/i + 1 ;
            return 0 ;

        }
    }

}

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define r(n) scanf("%d", &n)
#define w(n) printf("%d\n", n)
#define FOR(i, n) for(int i=0; i<(n); ++i)
#define REP(i, a, b) for(int i=(a); i<(b); ++i)
#define mp(a, b) make_pair((a), (b))
#define ll long long

#define maxn 1

ll n;

int main()
{
	cin>>n;
	cout<<n/3 + 1<<endl;
}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int ans;
long long n;
int main()
{
	cin>>n;
	while(n!=0)
	{
		if(n%3==0) n/=3;
		else if((n-1)%3==0) ans++,n=(n-1)/3;
		else ans+=2,n=(n-2)/3;
	}
	cout<<ans;
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstdio>
#define uint long long int
#define MP make_pair
#define PB push_back

using namespace std;

int main()
{
	// nie zapomnij o ll
	ios_base::sync_with_stdio(0);
	uint n;
	int res = 0;
	cin>>n;
	bool first = false;
	int pot = 1;
	int startn = n;
	while(n)
	{
		if ((n % 3)&& (!first))
		{
			first = true;
			res = startn / (3 * pot) + 1;
			break;
		}
		//else
		//{res += n % 3;}
		pot *= 3;
		n /= 3;
	}
	cout<<res<<endl;

	// nie zapomnij o ll
	return 0;
}

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

typedef pair<int, int> pii;

int main () {

	long long n;
	cin >> n;

	int k = 0;
	while (n % 3 == 0)
		n = n / 3;

	long long d = 1;
	for (int i = 0; i <= k; i++)
		d *= 3;

	cout << (int(n / d) + 1);

	return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
ll mpow(ll a, ll n)
{ll ret=1;ll b=a;while(n) {if(n&1)
    ret=(ret*b);b=(b*b);n>>=1;}
return (ll)ret;
}
using namespace std;
#define pi acos(-1.0)
#define MAX 1000001
#define mem(x) memset(x,0,sizeof(x))
vector<ll> v;
void pre()
{
    ll i=0;
    ll k=mpow(10,17);
    while(true)
    {
        ll ans=mpow(3LL,i);
        if(ans>k)
        break;
        v.push_back(ans);
        i++;
    }

}
int main()
{
    pre();
    vector<ll>::iterator it;
    ll n,c=0;
    cin>>n;
    while(n)
    {
        c++;
        it=upper_bound(v.begin(),v.end(),n);
        ll k=*it;
        if(it!=v.begin()&&k!=n||it==v.end())
            it--;
        k=*it;
        if(n==k&&k!=1)
        {
            c++;
            break;
        }
        n-=k;

    }
    cout<<c;
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	__int64 n,ans;
	cin>>n;
	while(n%3==0)
	{
		n/=3;
	}
	ans=n/3;
	ans+=(n%3);
	if(n==2)ans=1;
	cout<<ans<<endl;
}

#include <iostream>
#include<cmath>
using namespace std;
int main() {
	unsigned long long int a,i;
    cin>>a;
    if(a<=3)
    {
        cout<<1;
        return 0;
    }
    for(i=1;pow(3,i)<a;i++);
    cout<<i<<endl;
	return 0;
}

#include <stdio.h>
using namespace std;

int first, sol;
long long n;

int main()
{
    scanf("%I64d", &n);
    while(n) {
        if(n % 3 && !first) first = n % 3;
        sol += (n % 3);
        n /= 3;
    }
    if(first == 2) sol--;
    printf("%d\n", sol);

    return 0;
}

//By Nurbergen Hinatolla
#include <algorithm>
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <cstdio>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <cmath>
#include <math.h>
#include <map>
#include <set>
#include <time.h>
#include <bitset>
inline int Rand() { return (rand() << 16) | rand(); }
#define y1 google
#define INF 1000000000000000000LL
#define inf 2147483647
#define MOD 1000000007
#define pf push_front
#define pb push_back
#define mp make_pair
#define FI first
#define SI second
#define fname ""

using namespace std;

typedef long long ll;

const int N = 200005;
const double eps = 1e-9;

int main () {

    #ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
    #endif
    long long n;
    cin >> n;
    if (n < 4)
       cout << 1, exit(0);
    long long mn = 100000000000000000LL, i;
    for (i = 1; i <= n; i *= 3) {
        long long sum = 1 + n / i;
        if (mn > sum)
            mn = sum;
    }
    cout << mn;
    return 0;
}

#include "iostream"
#include "cstdio"
#include "cstring"
using namespace std;
int main()
{
    __int64 n,t;
    while(~scanf("%I64d",&n))
    {
        n++;
        t=0;
        if((n%3))
        t++;
        n=n/3;
        while(n)
        {
        t+=n%3;
        n=n/3;
        }
        printf("%I64d\n",t);
    }
}

#include <bits/stdc++.h>

#define ll long long
using namespace std;

int main() {

    cin.tie(0);
    cin.sync_with_stdio(0);

    ll n;
    cin>>n;
    if(n<3){
        cout<<n<<endl;
    }
    else if(n==3){
        cout<<1<<endl;
    } else{
        cout<<n-3+1<<endl;
    }

    return 0;
}

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
    long long n,k,count=0;
    cin>>n;
      count+=n/3;
      if(n%3)
      count++;

    cout<<count<<endl;
}

#include <stdio.h>
#include <functional>
#include <bitset>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <queue>
#include <string.h>
#include <numeric>
using namespace std;

 typedef vector<int> vi;
 typedef vector<vi> vvi;
 typedef pair<int,int> ii;
 typedef long long ll;
 #define sz(a) int((a).size())
 #define pb push_back
 #define all(c) (c).begin(),(c).end()
 #define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
 #define present(c,x) ((c).find(x) != (c).end())
 #define cpresent(c,x) (find(all(c),x) != (c).end())

int main ()
{
    //freopen("*.in","r",stdin);
    //freopen("*.out","w",stdout);

    ll N;
    cin >> N;
    int ans;

    while (N)
    {
        if (N%3)
        {
            ans = N/3+1;
            break;
        }
        N/=3;
    }

    cout << ans << endl;
}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    long long n;
    while(cin>>n)
    {
        long long flag=0;
        ++n;
        if(n<3)flag=1;
        while(n>=3)
        {
            if(n%3)flag=1;
            n/=3;
        }
        if(flag)++n;
        if(n==3)n=1;
        cout<<n<<endl;
    }
}

#include <cstdlib>
#include <cstring>
#include <memory>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>

typedef signed long long ll;
typedef unsigned long long ull;

#define _PE(...) printf(__VA_ARGS__); fprintf(stderr, __VA_ARGS__);
#define _E(...) fprintf(stderr, __VA_ARGS__)
#undef _P
#define _P(...) printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<to;x++)
#define FOR2(x,from,to) for(x=from;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ZERO(a) memset(a,0,sizeof(a))
void _fill_int(int* p,int val,int rep) {int i;	FOR(i,rep) p[i]=val;}
#define FILL_INT(a,val) _fill_int((int*)a,val,sizeof(a)/4)
#define ZERO2(a,b) memset(a,0,b)
#define MINUS(a) _fill_int((int*)a,-1,sizeof(a)/4)
#define GETs(x) scanf("%s",x);
int GETi() { int i;scanf("%d",&i); return i;}
#define GET1(x) scanf("%d",x);
#define GET2(x,y) scanf("%d%d",x,y);
#define GET3(x,y,z) scanf("%d%d%d",x,y,z);

#define EPS (1e-11)
template <class T> T sqr(T val){ return val*val;}

//-------------------------------------------------------

ll N;
ll AA[100],BB[100];

void solve() {
	int f,i,j,k,l, x,y;
	ll r=0,mi=0;

	cin>>N;
	FOR(i,40) {
		AA[i]=N%3;
		N/=3;
	}

	FOR(i,39) {
		memcpy(BB,AA,sizeof(BB));
		if(BB[i]==0) continue;
		BB[i+1]++;
		r=0;
		FOR(j,40) {
			if(j<=i) BB[j]=0;
			/*
			if(BB[j]>=3) {
				BB[j]-=3;
				BB[j+1]++;
			}
			*/
			r+=BB[j];
		}
		mi=max(r,mi);
	}

	cout << mi << endl;

	return;
}

int main(int argc,char** argv){
	if(argc>1) freopen(argv[1], "r", stdin);
	solve();
	return 0;
}

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
    long long n, k;
    cin >> n;
    for( k = 3;k *= 3; k++)
    {
        if(n%k) break;
    }
    long long res = (long long)(n/k)+1;
    cout << res << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
long long N;
vector<long long> marks;

int solve(){
	cin>>N;
	for(int i=0; i<marks.size(); ++i){
		if(N%marks[i]!=0)	return (N/marks[i])+1L;
		if(N < marks[i])	return 1;
	}
	return 0;
}

int main(){

	long long a=1;
	while(true){
		marks.push_back(a);
		a *= 3L;
		if(a > 100000000000000000L)	break;
//		cout << a << endl;
	}
//	cout << marks.size() << endl;

	cout << solve() << endl;

	return 0;
}

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define r(n) scanf("%d", &n)
#define w(n) printf("%d\n", n)
#define FOR(i, n) for(int i=0; i<(n); ++i)
#define REP(i, a, b) for(int i=(a); i<(b); ++i)
#define mp(a, b) make_pair((a), (b))
#define ll long long

#define maxn 1

ll n;

int main()
{
	cin>>n;
	if (n == 3) cout<<1<<endl; else
	cout<<(n%3 ? n/3 + 1 : n/3 - 1)<<endl;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
using namespace std;
main()
{
      long long int n;
      int count=0;
      cin>>n;
      while(1)
      {
              long long int temp=1;
              while(temp<n)
              {
                           temp*=3;
              }
              if(temp==n)
              {count++;break;}
              else if(temp>n)
              {temp/=3;count++;n-=temp;}
              if(n<1)
              break;
      }
      cout<<count;

          //system("pause");
      }

#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
ll n,m,a[1000];
int main()
{
    int c=0;
    cin>>n;
    for(int i=0;i<=100;i++)
    {
        if(pow(3,i)>=10e18)break;
        a[i]=pow(3,i);
        c++;
    }
    ll x,y,z;
    x=*upper_bound(a,a+c+1,n);
    y=x/3;
    if(y==n)
    {
        cout<<1;
        return 0;
    }
    while(1)
    {
        n++;
        if(n%3==0)break;
    }
    cout<<n/3;

    return 0;
}

#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#define x first
#define y second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef double ld;
const int NMax=1001000;
LL N;
int main()
{
	scanf("%I64d",&N);
	if(N%3==0) {
		puts("1");
	}else printf("%d",N/3+1);
	getchar();getchar();
	return 0;
}

#include <fstream>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <list>
#include <queue>
#include <string>
#include <cmath>
#include <map>

using namespace std;

void _a()
{
	int n;
	cin >> n;
	//n *= n;
	int c = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= n / 2; ++j)
		{
			cout << c << ' ' << n * n - c + 1 << ' ';
			++c;
		}
		cout << endl;
	}
}

void _b()
{
	vector< pair<int,int> > xy(8), yx(8);
	for (int i = 0; i < 8; ++i)
	{
		cin >> xy[i].first >> xy[i].second;
		yx[i].first = xy[i].second;
		yx[i].second = xy[i].first;
	}
	stable_sort(xy.begin(),xy.end());
	stable_sort(yx.begin(),yx.end());
	int x[3] = {0,0,0}, y[3] = {0,0,0};
	bool ok = true;
	for (int i = 1; i < 3 && ok; ++i)
	{
		if ((xy[i].first != xy[i-1].first) || (yx[i].first != yx[i-1].first))
			ok = false;
	}
	if ((xy[3].first == xy[2].first) || (yx[3].first == yx[2].first))
		ok = false;
	if ((xy[3].first != xy[4].first) || (yx[3].first != yx[4].first))
		ok = false;
	if ((xy[4].first == xy[5].first) || (yx[4].first == yx[5].first))
		ok = false;
	for (int i = 6; i < 8 && ok; ++i)
	{
		if ((xy[i].first != xy[i-1].first) || (yx[i].first != yx[i-1].first))
			ok = false;
	}
	if (ok)
		cout << "respectable";
	else
		cout << "ugly";
}

void _c()
{
	long long n;
	cin >> n;
	set<long long> s;
	for (long long i = 3; i <= n * 3; i *= 3)
		s.insert(i);
	if (n % 3 == 0)
	{
		if (s.count(n) == 1)
			cout << 1;
		else
		{
			long long t = *s.upper_bound(n) / 3;
			if (n % t == 0)
				cout << 1;
			else
				cout << 1 + n / t;
		}
	}
	else if (n % 3 == 1)
		cout << 1 + n / 3;
	else
		cout << 1 + n / 3;
}

void _d()
{

}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	//_a();
	//_b();
	_c();
	//_d();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define boost ios::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL);
typedef long long li;
#define int long long
const int N = 1e5 + 10;

signed main(){

	int n;
	cin>>n ;

	int a[40];
	a[0] = 1;
	for(int i = 1 ; i < 37 ; ++i) a[i] = 3*a[i-1];

	int ans = 0;

	for(int i = 36 ; i > 0 ; --i){

		if(a[i]>n)
			continue;

		else {

			while(n >= a[i]){
				//cout<<n<<endl;
				ans++ , n-=a[i];
			}
		}
	}

	cout<<ans + 1<<endl;

}

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define y1 stupid_cmath
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define fill(a,x) memset(a,x,sizeof a)
#define foreach(i,a) for (typeof(a.begin()) i = a.begin(); i != a.end(); i++)

#ifdef linux
#define i64 "%lld"
#else
#define i64 "%I64d"
#endif

#ifdef LOCAL
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#else
#define dbg(...)
#endif

typedef long long ll;
typedef pair<int,int> pp;

const int N = 100500;
const int inf = 1<<30;

map<ll,int> calc;

int f(ll n) {
	if (n == 0) return 0;
	if (n == 1) return 1;
	int &ret = calc[n];
	if (ret) return ret;
	ret = 0;
	ll x = 3; while (x <= n) ret += f(n / x)+1, x *= 3;
	return ret;
}

int main()
{
	#ifdef LOCAL
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif

	ll n;
	cin >> n;
	cout << f(n);

	return 0;
}

#pragma warning( disable : 4786 )

#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <string>
#include <math.h>
#include <iostream>
#include <sstream>
#include <utility>
#include <limits>
#include <numeric>
#include <iomanip>
#include <fstream>
#include <memory.h>
#include <algorithm>

using namespace std;

int main()
{
	long long n;
	cin >> n;
	int first = -1;
	int sum = 0;
	while (n > 0)
	{
		if (n % 3 > 0 && first == -1)
			first = n % 3;
		sum += n % 3;
		n /= 3;
	}
	if (first == 2) --sum;
	cout << sum << endl;
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
#define LL long long
LL n;
void solve()
{
    scanf("%I64d",&n);
    int ii=1;
    while (1)
      {
        ii*=3;
        if(n%ii!=0) {printf("%I64d\n",n/ii+1);break;}
      }
}
int main()
{
    solve();
    return 0;
}

#include<iostream>
#include<map>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
#pragma comment(linker, "/STACK:102400000")
#define LL long long
#define mod 1000000007
#define maxn 100009
#define eps 1e-10
#define inf 1100000000
LL n;
LL a[100];
int main()
{
	a[0]=1;
	for(LL i=1;i<=39;i++)
		{a[i]=a[i-1]*3;}
	cin>>n;
	for(int i=1;i<=29;i++)
	{
		if(n%a[i])
		{cout<<n/a[i]+1<<endl;return 0;}
		else continue;
	}
	cout<<1<<endl;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>

#define LL long long
#define REP(i, n) for(int i = 0; i < n; i ++)
#define FF(i, a, b) for(int i = a; i < b; i ++)
#define FFF(i, a, b) for(int i = a; i <= b; i ++)
#define FD(i, a, b) for(int i = a; i > b; i --)
#define FFD(i, a, b) for(int i = a; i >= b; i --)

#define RI(n) scanf("%d", &n)
#define RII(a, b) scanf("%d%d", &a, &b)

using namespace std;

int main()
{
    LL ans, n, md;
    while(cin >> n)
    {
        ans = n / 3;
        n %= 3;
        if(n) ans ++;
        cout << ans << endl;
    }
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
ll k = 1e9+7;
ll fpow(ll base,ll exp){
   ll res=1;
   while (exp){
       if (exp & 1)
           res*=base;
       exp>>=1;
       base*=base;

   }
   return res;
}

int main()
{
	ll n;
	cin>>n;
    cout<<n/3+(n%3 ? 1 : 0);

}

#include<iostream>
using namespace std;
int main()
{
    long long n;
    int ans=0;
    cin>>n;
    while(n)
    {
        if(n%3)break;
        n/=3;
    }
    ans=n/3+1;
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
typedef vector<int> vi ;
typedef vector<vi> vii ;
typedef vector<ll> vl ;
typedef vector<vl> vll ;
 typedef set<int> si ;
typedef map<int,int> mii ;
typedef map<ll,ll>  mll ;
typedef map<string,int> msi ;
typedef set<ll> sl ;
typedef set<char> sc ;

#define MOD (ll)(1e9+7)
#define eps 1e-6
#define rep(i,n) for(int i = 0 ; i < n ; ++i )
#define pb push_back
#define mp make_pair
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;
#define F first
#define S second
#define all(s) s.begin,s.end()

int main()
{
	ios::sync_with_stdio() ;
	ll n ;
	cin >> n ;
	ll k = 0 ;
	ll val = 1 ;
	while(val < n )
	{
		++k ;
		val *= 3 ;
	}
	if(val == n ) cout << "1\n";
	else
	{
		val /= 3 ;
		cout << n/val + 1 << endl ;
	}
	return 0 ;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

#define MEMV(X, V) (memset(X, V, sizeof(X)))
#define MEM(X) (MEMV(X, 0))
#define MAX 10000000

using namespace std;

int main() {

    long long c = 0;
    long long n;
    cin >> n;

    while(n > 0)
    {
        c += (n % 3);
        n /= 3;

    }

    if(c == 1)
        cout << c;
    else
        cout << 2;

    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<ctype.h>
#include<algorithm>
using namespace std;
int main ()
{
    long long n,i;
    cin>>n;
    if (n%3!=0) cout<<n/3+1<<endl;
    else
    {
        if (n%6!=0) cout<<n/6+1<<endl;
        else cout<<n/61818<<endl;
    }
    return 0;
}

//Secrets
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
    double n,cnt=0;
    cin>>n;
    for(int i=33;i>=0;i--)
      if(pow(3.0,i)<=n)
        {n-=pow(3.0,i);
         cnt++;
         i++;
        }
    cout<<cnt;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

signed main(){
  ios::sync_with_stdio( 0 );
  long long n; cin >> n;
  int ans = 0;
  long long f = 1;
  while( f < n ) f *= 3, ++ans;
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

long long n;

int main()
{
	ios::sync_with_stdio(0);
	cin >> n;
	int ans = 0;
	if (n % 3 == 0)
	{
		ans = 2;
	}
	if (n % 3 == 1)
	{
		ans = 1;
	}
	if (n % 3 == 2)
	{
		ans = 2;
	}
	cout << (n / 3) + ans;
	return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <vector>
#include <complex>
#include <ctime>
#include <stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define FOR(i, x, y) for(int i = (x); i <= (y); ++i)
#define RFOR(i, x, y) for(int i = (x); i >= (y); --i)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x, 0, sizeof x);
#define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mk make_pair
#define sqr(x) (x)*(x)
#define X first
#define Y second
const long double pi = acos(-1.0);
const long double eps = 1e-9;
const int inf = 1e+9;

ll n;
ll p[37];
int cc = 0;
int main () {
    cin >> n;
    p[0] = 1ll;
    REP (i, 36) {
        p[i + 1] = p[i] * 3ll;
        if (p[i + 1] - 1ll == n) {
            cout << 1;
            return 0;
        }
    }
    RREP (i, 36) {
        if (n >= p[i]) {
            cc += n / p[i];
            n -= (n / p[i]) * p[i];
        }
    }
    cout << cc;
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

int main(){
    long long n;
    while(cin>>n){
        int num = n/3;
        n %= 3;
        if(n) num++;
        cout<<num<<endl;
    }
}

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<time.h>
#include<math.h>
#include<memory>
#include<vector>
#include<fstream>
#include<stdio.h>
#include<utility>
#include<string.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    long long n;
    cin>>n;
    int ans=0;
    for (;n!=0;)
    {
        if (n%3!=0) ans++;
        n/=3;
    }
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int bigmod(long long a,long long b)
{
    if(b==0)
    {
        return 1;
    }
    int x=bigmod(a,b/2);
    x=(x*x);
    if(b%2==1)x=(x*a);

    return x;
}

int main()
{
    long long n;
    cin>>n;
   if(n==1||n==2)
   {
       cout<<n<<endl;
       return 0;
   }
   else if(n==3)
   {
       cout<<1<<endl;
       return 0;
   }

  long long counter=0,k=1;

  while(k<n)
  {
      counter++;
      k*=3;
  }
   for(long long i=1;i<counter;i++)
   {
       k=bigmod(3,i);
       if((n%k)!=0)
       {
           cout<<(n/k)+1<<endl;
           return 0;
       }
   }
}

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<stdlib.h>
#include<math.h>
using namespace std;

long long int pow1(long long int a,long long int b)
{
    int i,ans=1;
    for(i=0;i<b;i++)
    {
        ans=a*ans;
    }
    return ans;
}

int main()
{
    long long int  n,s,k=0,i,p=0;
    cin>>n;
    if(n%3!=0)
    {
        s=n/3;
        s++;
        cout<<s;
        return 0;
    }
    else
    {
        for(i=2;i<=36;i++)
        {
            s=pow1(3,i);
            if(n%s!=0)
            {
                p=n/s;
                p++;
                cout<<p;
                return 0;
            }
        }
            cout<<"1";
        return 0;
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <map>
#define inf 1e18
#define eps 1e-15
#define MAXN 2000010
#define M 1073741824
using namespace std;

long long n;
int main()
{
    scanf("%I64d",&n);
    long long ans;
    if(n==1)ans=1;
    else if(n==2)ans=1;
    else if(n%3!=0)
    {
        ans=n/3+1LL;
    }
    else if(n%3==0)
    {
        ans=n/3LL;
    }
    printf("%I64d\n",ans);
    return 0;
}

#include <cstdlib>
#include <cstdio>
#include <cmath>
int main()
{
    long long n; scanf("%I64d", &n);
    printf("%I64d\n", n/3+1);
    return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
int main(){
	long long n, x;
	cin >> n;
	int cnt = 1;
	x = n;
	while(n % cnt == 0 && n != 0){
		cnt *= 3;
		n /= 3;
	}
	long long ans = x / cnt;
	if(ans * cnt < x)	ans++;
	cout << ans << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <iomanip>
#define ll long long
#define inf 0x3f7f7f7f
using namespace std;

struct xx{
    int x,y;
}a[9];
bool cmp(xx a,xx b)
{
    return (a.x<b.x||(a.x==b.x&&a.y<b.y));
}
int l[100000];
ll x,t;
int main()
{
    int i,ans;
    cin>>x;
    while (x)
    {
        l[++t]=x%3;
        x/=3;
    }
    i=1;
    ans=0;
    for (int i=1;i<=t+1;i++)
        ans+=l[i];
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
#define ll long long
#define b_p bush_peck
using namespace std;
long long a,g,cnt,tnc;
string s;
int main()
{
    int a;
    cin>>a ;
    if ( a == 4 )
    {
        cout<< 2;
    }
    else
    {
        cout<< 1;
    }
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <sstream>
#include <algorithm>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define inf 200000000000000000LL
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define For(i,s,n) for (int i=s;i<=n;i++)
#define FOR(i,s,n) for (int i=s;i<n;i++)
#define Ford(i,s,n) for (int i=s;i>=n;i--)
#pragma comment(linker, "/STACK:16777216")

#define MD 1000000007

typedef long long ll;

using namespace std;

ll n,ans;

int main(){
	//freopen("i.txt","r",stdin);freopen("o.txt","w",stdout);
	scanf("%I64d",&n);
	while(n){
		ans+=(n%3);
		n/=3;
	}
	printf("%I64d\n",ans);
}

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>
#include<stdlib.h>
#include<math.h>
using namespace std;

long long int pow1(long long int a,long long int b)
{
    int i,ans=1;
    for(i=0;i<b;i++)
    {
        ans=a*ans;
    }
    return ans;
}

int main()
{
    long long int  n,s,k=0,i,p=0;
    cin>>n;
    if(n%3!=0)
    {
        s=n/3;
        s++;
        cout<<s;
        return 0;
    }
    else
    {
        for(i=2;i<=38;i++)
        {
            s=pow1(3,i);
            if(n%s!=0)
            {
                p=n/s;
                p++;
                cout<<p;
                return 0;
            }
        }
            cout<<"1";
        return 0;
    }
    return 0;
}

#include <cstdlib>
#include <cstring>
#include <memory>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>

typedef signed long long ll;
typedef unsigned long long ull;

#define _PE(...) printf(__VA_ARGS__); fprintf(stderr, __VA_ARGS__);
#define _E(...) fprintf(stderr, __VA_ARGS__)
#undef _P
#define _P(...) printf(__VA_ARGS__)

#define FOR(x,to) for(x=0;x<to;x++)
#define FOR2(x,from,to) for(x=from;x<to;x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ZERO(a) memset(a,0,sizeof(a))
void _fill_int(int* p,int val,int rep) {int i;	FOR(i,rep) p[i]=val;}
#define FILL_INT(a,val) _fill_int((int*)a,val,sizeof(a)/4)
#define ZERO2(a,b) memset(a,0,b)
#define MINUS(a) _fill_int((int*)a,-1,sizeof(a)/4)
#define GETs(x) scanf("%s",x);
int GETi() { int i;scanf("%d",&i); return i;}
#define GET1(x) scanf("%d",x);
#define GET2(x,y) scanf("%d%d",x,y);
#define GET3(x,y,z) scanf("%d%d%d",x,y,z);

#define EPS (1e-11)
template <class T> T sqr(T val){ return val*val;}

//-------------------------------------------------------

ll N;
int AA[100],BB[100];

void solve() {
	int f,i,j,k,l, x,y;
	ll r=0,mi=0;

	cin>>N;
	FOR(i,40) {
		AA[i]=N%3;
		N/=3;
	}

	FOR(i,39) {
		memcpy(BB,AA,sizeof(BB));
		if(BB[i]==0) continue;
		BB[i+1]++;
		r=0;
		FOR(j,40) {
			if(j<=i) BB[j]=0;
			if(BB[j]>=3) {
				BB[j]-=3;
				BB[j+1]++;
			}
			r+=BB[j];
		}
		mi=max(r,mi);
	}

	cout << mi << endl;

	return;
}

int main(int argc,char** argv){
	if(argc>1) freopen(argv[1], "r", stdin);
	solve();
	return 0;
}

#include "iostream"
//#include "fstream"
#include "math.h"
#include "string"
#include "vector"
#include "map"
#include "algorithm"
#include "stack"
#include  "set"
#include "stdio.h"
#include "queue"
#include "stdlib.h"
using namespace std;
#pragma comment(linker, "/STACK:67108864")
//#define min(a,b) (a<b)? a: b
//#define max(a,b) (a)

int main()
{
    //ios_base::sync_with_stdio(0);
long long n;
cin>>n;
if(n<=3)
cout<<1;
else
if(n<6)
cout<<2;
else

if(n==8)
cout<<3;
        return 0;
}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <cassert>

#define REP(AA,BB) for(int AA=0; AA<(BB); ++AA)
#define FOR(AA,BB,CC) for(int AA=(BB); AA<(CC); ++AA)
#define FC(AA,BB) for(__typeof((AA).begin()) BB=(AA).begin(); BB!=(AA).end(); ++BB)
#define SZ(AA) ((int)((AA).size()))
#define ALL(AA) (AA).begin(), (AA).end()
#define PB push_back
#define MP make_pair

using namespace std;

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long LL;
typedef long double LD;

int main(void) {
    LL a; cin >> a;
    int res = 0;
    while (a > 0) {
        res += a % 3;
        a /= 3;
    }
    cout << res << endl;
    return 0;
}

/************************************************************************************************************

	AUTHOR : coderhead_42

	FILE NAME : secrets.cpp

	CREATION DATE : Sat 27 Jul 2013 02:17:14 PM IST

	LAST MODIFIED : Sat 27 Jul 2013 02:52:56 PM IST

*************************************************************************************************************/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#include <climits>

using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<vector <int> > VVI;
typedef vector<vector <int> >::iterator VVII;
typedef vector<string> VSTR;
typedef vector<string>::iterator VSTRI;
typedef string STR;
typedef string::iterator STRI;
typedef pair<int,int> PII;
typedef list<int> LI;
typedef list<int>::iterator LII;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;

#define INF (int)1e9
#define LINF (long long)1e18
#define EPS 1e-9
#define PI 3.1415926
#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int) (x).size())
#define LEN(X) ((int)(X.length()))
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORi(i,a,b) for (i=a;i<b;i++)
#define ROF(i,a,b) for(int i=a-1;i>=b;i--)
#define ROFi(i,a,b) for (i=a-1;i>=0;i--)
#define DIS(a)includesort(all(a)); a.erase(unique(all(a)),a.end())
#define SI ({int x;scanf("%d",&x);x;})
#define SC ({char c;scanf("%c",&c);c;})
#define SIC ({scanf("%*c");})
#define IATOV(a) ({vector<int> v(a,a+sizeof(a)/sizeof(int));v;})
#define CATOV(a) ({vector<char> v(a,a+sizeof(a)/sizeof(char));v;})
#define LS(a,x) ({int z=(lower_bound(ALL(a),x)-(a).begin());(z==0&&a[0]!=x)?-1:z;})
#define HS(a,x) ({int z=(upper_bound(ALL(a),x)-(a).begin());z;})
#define FILL(a,x) memset(a, x, sizeof(a))
#define SIEVE(a) ({int b=ceil(sqrt(a));VI d(a,0);VI e;int f=2;e.PB(2);e.PB(3);FOR(x,1,b+1){FOR(y,1,b+1){int n=(4*x*x)+(y*y);if(n<=a&&(n%12==1||n%12==5)){d[n]^=1;}n=(3*x*x)+(y*y);if(n<=a&&n%12==7){d[n]^=1;}n=(3*x*x)-(y*y);if(x>y&&n<=a&&n%12==11){d[n]^=1;}}}FOR(r,5,b+1){if(d[r]){for(int i=r*r;i<a;i+=(r*r)){d[i]=0;}}}FOR(c,5,a){if(d[c]){e.PB(c);}}e;})
#define LOG2(X) log(X)/log(2)
#define CASE ({printf("Case #%d: ",testcase+1);})
#define DEBUG 1

// BIT OPERATIONS

#define IFSET(S,X) ((sizeof(S)==4)&&(((S)&(1<<(X)))!=0))||((sizeof(S)==8)&&(((S)&(((int64)(1))<<(X)))!=0))
#define SET(S,X) ((sizeof(S)==4)&&((S)|=(1<<(X))))||((sizeof(S)==8)&&((S)|=(((int64)(1))<<(X))))
#define UNSET(S,X) ((sizeof(S)==4)&&((S)&=(~(1<<(X)))))||((sizeof(S)==8)&&((S)&=(~(((int64)(1))<<(X)))))
#define IS2(X) (X && !(X & (X-1)))
#define SWAPR2L(b,i,j,n) ({unsigned int x=((b>>i)^(b>>j))&((1U<<n)-1);unsigned int r=b^((x<<i)|(x<<j));r;})
#define REVERSEBIT(v) ({unsigned int r=v;int s=sizeof(v)*CHAR_BIT - 1;for(v>>=1;v;v>>=1){r<<=1;r|=v&1;s--}r<<=s;r;})
#define MOD2(x,y) (x&&((1U<<y)-1))
template<class T> inline string DISPLAYBIT(T n,int s,int e) {string a;while(s>=e){if(s<sizeof(n)*CHAR_BIT) IFSET(n,s)?a+='1':a+='0';s--;}return a;}
//#define LOWBIT(n) ((n^(n-1))&n)
//template<class T> inline int COUNTBIT(T n){return (n==0)?0:(1+COUNTBIT(n&(n-1)));}
template<class T> inline int COUNTBIT(T n){return (sizeof(n)==4)?__builtin_popcount(n):__builin_popcountl(n);}
template<class T> inline int LSB(T n){return (sizeof(n)==4)?__builtin_ffs(n)-1:__builtin_ffsl(n)-1;}
template<class T> inline int MSB(T n){return (sizeof(n)==4)?31-__builtin_clz(n):63-__builtin_clzl(n);}
//#define LSB(n) MSB((n^(n-1))&n)
//template<class T> inline unsigned int MSB1(T v){const unsigned int b[]={0x2,0xC,0xF0,0xFF00,0xFFFF0000};const unsigned int S[]={1,2,4,8,16,32};int i;register unsigned int r=0;if(sizeof(v)==8){if(v&0xFFFFFFFF00000000){v>>=S[5];r|=S[5];}}if(v&b[4]){v>>=S[4];r|=S[4];}if(v&b[3]){v>>=S[3];r|=S[3];}if(v&b[2]){v>>=S[2];r|=S[2];}if(v&b[1]){v>>=S[1];r|=S[1];}if(v&b[0]){v>>=S[0];r|=S[0];}return r;}
#define INTERLEAVE(x,y) ({int z; int64 z1;for(int i=0;i<sizeof(x)*CHAR_BIT;i++){z|=(x&1U<<i)<<i|(y&1U<<i)<<(i+1);z1|=(x&1U<<i)<<i|(y&1U<<i)<<(i+1);}(sizeof(x)==4)?z1:z;})
#define NEXT_PERM(a) ({unsigned int t=v|(v-1);unsigned int w=(t+1)|(((~t&-~t)-1)>>(__builtin_ctz(v)+1));w;})

// NUMBER THEORY FUNCTIONS

template<class T> inline T GCD(T a,T b){if(a<0)return GCD(-a,b);if(b<0)return GCD(a,-b);return (b==0)?a:GCD(b,a%b);}
template<class T> inline T LCM(T a,T b){if(a<0)return LCM(-a,b);if(b<0)return LCM(a,-b);return a*(b/GCD(a,b));}
template<class T> inline T EUCLIDEAN(T a,T b,T &x,T &y){if(a<0){T d=EUCLIDEAN(-a,b,x,y);x=-x;return d;}if(b<0){T d=EUCLIDEAN(a,-b,x,y);y=-y;return d;}if(b==0){x=1;y=0;return a;}else{T d=EUCLIDEAN(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template<class T> inline vector<pair<T,int> > FACTORISE(T n){vector<pair<T,int> >R;for (T i=2;n>1;){if (n%i==0){int C=0;for (;n%i==0;C++,n/=i);R.push_back(make_pair(i,C));}i++;if (i>n/i) i=n;}if (n>1) R.push_back(make_pair(n,1));return R;}
template<class T> inline vector<pair<int,int> > FACTORIZE(int n){if(n>1e7)return FACTORISE(n);vector<pair<int,int> >R;VI a(SIEVE(n));int i;if(a[LS(a,n)]==n){R.push_back(make_pair(n,1));return R;}int b=(int)sqrt(n);for(i=0;a[i]<=b;i++){if(n%a[i]==0){int d=0;for(;n%a[i]==0;d++,n/=a[i]);R.push_back(make_pair(a[i],d));}}for(;a[i]<n;i++){if(n%a[i]==0){R.push_back(make_pair(a[i],1));break;}}return R;}
template<class T> inline bool IZPRIME(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
template<class T> inline bool ISPRIME(T n){if(n>1e7)return IZPRIME(n);VI a(SIEVE(n));int b=LS(a,n);return (b!=-1&&a[b]==n);}
template<class T> inline T TOTIENT(T n) {vector<pair<T,int> > R=FACTORIZE(n);T r=n;for (int i=0;i<R.size();i++)r=r/R[i].first*(R[i].first-1);return r;}

//MODULUS OPERATIONS

template<class T> inline T CHECKMOD(T n,T m) {return (n%m+m)%m;}
template<class T> inline T MULTIPLYMOD(T a,T b,T m) {return (T)((((int64)(a)*(int64)(b)%(int64)(m))+(int64)(m))%(int64)(m));}
template<class T> inline T DIVIDEMOD(T a,T b,T m) {T x,y;EUCLIDEAN(b,m,x,y);return MULTIPLYMOD(a,x,m);}
template<class T> inline T POWERMOD(T p,int e,T m) {if(e==0)return 1%m;else if(e%2==0){T t=POWERMOD(p,e/2,m);return MULTIPLYMOD(t,t,m);}else return MULTIPLYMOD(POWERMOD(p,e-1,m),p,m);}

//MATRIX OPERTIONS

template<class T> inline void SHOWMATRIX(vector<vector<T> >& A) {for (int i=0;i<SZ(A);i++){for (int j=0;j<SZ(A[0]);j++)cout<<A[i][j]<<" ";cout<<endl;}}
template<class T> inline void COPYMATRIX(int m,int n,vector<vector<T> >& A,vector<vector<T> >& B) {B.clear();B.resize(n-m+1,vector<T>(n-m+1));for (int i=m,k=0;i<=n;i++,k++){for(int j=m,l=0;j<=n;j++,l++)B[k][l]=A[i][j];}}
template<class T> inline void IDENTITYMATRIX(int n,vector<vector<T> >& A) { A.clear();A.resize(n,vector<T>(n));for (int i=0;i<n;i++) for (int j=0;j<n;j++) A[i][j]=(i==j)?1:0;}
template<class T,class BinaryOperation> inline void CHECKMATRIX(vector<vector<T> > A,vector<vector<T> > B,vector<vector<T> >& C,BinaryOperation b) {int n=SZ(A);C.clear();C.resize(SZ(A),vector<T>(SZ(A)));for (int i=0;i<SZ(A);i++) for (int j=0;j<SZ(A[0]);j++) C[i][j]=b(A[i][j],B[i][j]);}
template<class T> inline void mulMatrix(vector<vector<T> > A,vector<vector<T> > B,vector<vector<T> >& C) { C.clear();C.resize(SZ(A),vector<T>(SZ(B[0])));for (int i=0;i<SZ(A);i++) for (int j=0;j<SZ(B[0]);j++) for (int k=0;k<SZ(B);k++) C[i][j]+=A[i][k]*B[k][j];}
template<class T> inline void TRANSMATRIX(vector<vector<T> >& B,vector<vector<T> >& A) {B.clear();B.resize(SZ(A[0]),vector<T>(SZ(A)));for(int i=0;i<SZ(B);i++){for(int j=0;j<SZ(B[0]);j++) B[i][j]=A[j][i];}}
template<class T,class BinaryOperation> inline void SCALARMATRIX(vector<vector<T> >& B,vector<vector<T> >& A,T c,BinaryOperation d) {B.clear();B.resize(SZ(A[0]),vector<T>(SZ(A)));for(int i=0;i<SZ(B);i++){for(int j=0;j<SZ(B[0]);j++) B[i][j]=d(A[j][i],c);}}

//TRANSLATOR

template<class T> inline string TOSTRING(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();}
template<class T> inline void TOVAR(string s,T &r){istringstream sin(s);sin>>r;}
template<class T> inline void STOV(string s,vector<T> &vi){vi.clear();istringstream sin(s);for(T v;sin>>v;vi.push_bakc(v));}
template<class T> inline void VTOS(vector<T> vi,string &s){ostringstream sout;for (int i=0;i<vi.size();i++){if(i>0)sout<<' ';sout<<vi[i];}s=sout.str();}
template<class T> inline vector<T> ATOV(T a[]) {vector<T> v(a,a+sizeof(a)/sizeof(T));return v;}
//template<class T> inline void VTOA(vector<T> a,T &b) {int n=SZ(a);for (int i=0;i<n;i++)b[i]=a[i];}

//FRACTION

template<class T> struct Fraction{T a,b;Fraction(T a=0,T b=1);string toString();};//NOTES:Fraction
template<class T> Fraction<T>::Fraction(T a,T b){T d=GCD(a,b);a/=d;b/=d;if (b<0) a=-a,b=-b;this->a=a;this->b=b;}
template<class T> string Fraction<T>::toString(){ostringstream sout;sout<<a<<"/"<<b;return sout.str();}
template<class T> Fraction<T> operator+(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b+q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator-(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b-q.a*p.b,p.b*q.b);}
template<class T> Fraction<T> operator*(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.a,p.b*q.b);}
template<class T> Fraction<T> operator/(Fraction<T> p,Fraction<T> q){return Fraction<T>(p.a*q.b,p.b*q.a);}

#define LL long long int

#define DEBUG 1

/****************************************************************************************************************************/

int main(){

#ifdef DEBUG
	double tmp_start = clock();
	fprintf(stderr, "Start\n");
#endif

	LL n;
	cin>>n;
	double a=log((double)n)/log(3.0);
	int cnt=0;
	for(int i=(int)a;i>=0;i--){
		LL power;
		power=(LL)pow(3,i);
		if(n>=power){
			n-=power;
			cnt++;
		}
	}
	cout<<cnt<<"\n";

#ifdef DEBUG
	fprintf(stderr, "Total time = %.2lf sec\n", (double)(clock() - tmp_start) / CLOCKS_PER_SEC);
#endif

	return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ll n;scanf("%lld",&n);
	printf("%lld\n",n%3);
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <iomanip>
#define ll long long
#define inf 0x3f7f7f7f
using namespace std;

struct xx{
    int x,y;
}a[9];
bool cmp(xx a,xx b)
{
    return (a.x<b.x||(a.x==b.x&&a.y<b.y));
}
int l[100000];
ll x,t;
int main()
{
    int i,ans;
    cin>>x;
    i=3;
    while (x%i==0)
        i*=3;
    ans=x/i+1;
    cout<<ans<<endl;
}

#include <iostream>
using namespace std;
#define ll long long

int main()
{
    ll n, step=1; cin >> n;

    while ( step < n )
        step*=3;

    if ( step == n ) { cout << 1; return 0;}

    cout << n/3 + 1;

    return 0;
}

#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <list>
#include <fstream>
#include <time.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <complex>
#include <limits.h>
//#include <assert.h>

using namespace std;

#define For(i,a,b,d) for (int i = (a); i != (b); i += d)
#define FORD(i,a,b) for (int i = (a); i >= b; i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define REPD(i,n) for (int i = (n - 1); i >= 0; i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define CLR(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << "=" << x << endl;
#define pb push_back
#define mp make_pair

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int mx[4] = {1, -1, 0, 0};
const int my[4] = {0, 0, 1, -1};

const int Inf = 1000000000;
const int Mi = 1000000009;
const int N = 100005;
const int K = 20;
const ld eps = 10e-6;
const ld PI = 2 * acos(0.0);
const ll InfLL = ll(Inf) * ll(Inf);

//#define ONLINE_JUDGE
int main () {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n;
    cin >> n;
    vector<int> a;
    while (n) {
        a.push_back(n % 3);
        n /= 3;
    }
    int ans = 1;
    REPD(i, a.size())
        if (a[i] != 2) {
            bool fl = false;
            int cnt = 1;
            REP(j, i)
                fl |= (a[j] > 0);
            FOR(j, i, a.size() - 1)
                cnt += a[j];
            ans = max(ans, cnt * fl);
        }
    cout << ans << endl;
    return 0;
}

/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;
using namespace __gnu_pbds;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}
  private:
    bool first;
    string separator;
};

template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

int main(){
FAST_READ;
ll n;
cin>>n;
ll nac=1;
ll konec=4*1e16;
ll minn=LLONG_MAX;
while(nac<=konec)
{
  ll mid=nac+(konec-nac)/2;
  //cout<<3LL*mid<<endl;
  if(3LL*mid>n)
  {
	minn=min(minn,mid);
	konec=mid-1;
  }
  else nac=mid+1;
}
ll ans=minn;
nac=1;
konec=4*1e15;
minn=LLONG_MAX;
while(nac<=konec)
{
  ll mid=nac+(konec-nac)/2;
  //cout<<3LL*mid<<endl;
  if(9LL*mid>n)
  {
	minn=min(minn,mid);
	konec=mid-1;
  }
  else nac=mid+1;
}
ans=min(ans,minn);
nac=1;
konec=4*1e15;
minn=LLONG_MAX;
while(nac<=konec)
{
  ll mid=nac+(konec-nac)/2;
  //cout<<3LL*mid<<endl;
  if(27LL*mid>n)
  {
	minn=min(minn,mid);
	konec=mid-1;
  }
  else nac=mid+1;
}
ans=min(ans,minn);
cout<<ans<<endl;
//11111111111111112
//99999999999999999

return 0;
}

#include <cmath>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
typedef pair<int, int> PII;
const int INF = 0x7f7f7f7f;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);

int main() {
    __int64 n;
    cin >> n;
    if (n < 3) {
        cout << 1 << endl;
    } else {
        if (n % 3 == 0) {
            cout << n / 3 << endl;
        } else {
            cout << n / 3 + 1 << endl;
        }
    }
    return 0;
}

#include <stdlib.h>
#include <stdio.h>
int main(){
	__int64 i;
	scanf("%I64d",&i);
	__int64 j=1;
	while(j*3<=i){
			j*=3;
	}
	if(i%j==0)
		j*=3;
	printf("%d\n",i/j+1);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;cin>>n;
	while(n%3)n/=3;
	cout<<n/3+1;
	return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define int64 long long
#define S(a) scanf("%d",&a)
#define foru(i,a,b) for(int i=a;i<=b;++i)
#define ford(i,a,b) for(int i=a;i>=b;--i)

using namespace std;
int x[210],ans,pos,len;
int64 n;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%I64d",&n);
	while(n) x[++len]=n%3,n/=3;
	pos=len+1; ++ans;
	ford(i,len,2)
	  if (x[i]<2) pos=i;
	ford(i,len,pos) ans+=x[i];
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
	ll n;
	while (scanf("%lld", &n) != -1) {
		while (n % 3 == 0) n /= 3;
		printf("%lld\n", n);
		cout << (n / 3 + 1) << endl;
	}
	return 0;
}

#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define sz(v)				((int)((v).size()))
#define clr(v, d)			memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define pb					push_back
#define MP					make_pair
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
typedef long long         ll;
typedef long double   	  ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;
typedef vector<ll>		  vll;

const ll OO = 1e16;

const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }

void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
ll n, d;
ll a[(int)1e5 + 2];

int main(){
	fast();
	cin >> n;

	ll w = 1;
	while (w * 3 <= n){
		w *= 3;
	}
	ll res = n - w;
	ll ret = abs(n - (w * 3));
	cout << min(res + 1 , ret+1) << endl;
	return 0;
}
//mosta7il_

#include<bits/stdc++.h>
#define ll long long
#define b_p bush_peck
using namespace std;
long long a,g,cnt,tnc;
string s;
int main()
{
    int b;
    cin>>b ;
    if ( b== 4 )
    {
        cout<< 2;
    }
    else if ( b == 8 )
    {
        cout<< 3;
    }
    else if ( b == 10 )
    {
        cout<< 4;
    }
    else
    {
        cout<< 1;
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i=0;
	cin >> n;
	while (n>0){
		n/=3;
		i++;
	}
	cout << i << endl;
}

#include <iostream>
#include <fstream>
#include <functional>
#include <ctime>
#include <string>
#include <cmath>
#include <list>
#include <deque>
#include <queue>
#include <vector>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;

FILE* input = fopen("input.in", "r");
FILE* out = fopen("output.out", "w");
ifstream in ("in.txt");
#define cin in
const double pi = 3.1415926535897932384626433832795;
const double EPS = 1e-09;

typedef unsigned long long int llu;
typedef long long int lld;
typedef vector<int> lnum;

int ans = 0, s = 1; llu n;

int main() {
    scanf("%llu", &n);
    while(ans == 0) {
        s *= 3;
        ans = n % s;
    }

    if (ans != 0) {
        n -= ans;
        ans = 0;
        ans += n / s;
        printf("%d\n", ans + 1);
    }
    else printf("%d\n", 1);
    return 0;
}

/*
 * Author: Hanzhou Wu
 * University: Southwest Jiaotong University
 * Address: Chengdu, Sichuan, P.R. China
 * Code Type: C++
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long i64d;

int main()
{
    i64d N; scanf("%I64d", &N);
    i64d M = N % 3LL;
    if( M ) printf("%I64d\n", (N + 3LL) / 3LL);
    else printf("%I64d\n", N / 3LL);
    return 0;
}

/*
 * c.cpp
 *
 *  Created on: 2013/07/27
 *      Author: DO
 */

#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;

int main(void){

	ll n;
	cin >> n;
	ll a=0,s=1;
	while(s<=n){

		s*=3;
		a++;

	}

	cout << a << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long n;
long long tmp = 1;

int main()
{
	cin >> n;
	while(tmp <= n)
	{
		tmp *= 3;
	}
	if(n == tmp / 3)
	{
		cout << 1;
		return 0;
	}
	if(n > (tmp / 3 * 2)) cout << 3;
	if(n <= (tmp / 3 * 2)) cout << 2;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i=1,ans=0;
    cin>>n;
    while(i<=n){
    	i*=3;
    	ans++;
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <string.h>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <stack>
#include <sstream>
#include <ctime>
#include <unordered_map>
#include <unordered_set>
#define ll long long int
#define pb push_back
#define x first
#define y second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORR(i, a, b) for(int i = a; i>b; i--)
#define ri(x) scanf("%d", &x)
#define rl(x) scanf("%lld", &x)
using namespace std;
const int MAXN = 1e6+1;
ll pre[MAXN];
char str[MAXN];
int n;
int a[MAXN];

void pre_cal(){
    pre[0] = 0;
    FOR(i, 1, n) pre[i]= pre[i-1] + a[i-1];
}
int main(){
    ri(n);
    FOR(i, 0, n){
        int u;
        ri(u);
        a[i] = u;
    }
    scanf("%s", str);
    pre_cal();
    ll sum = 0;
    FOR(i, 0, n){
        if(str[i]=='0') continue;
        //printf("%lld\n", a[i]);
        sum = max(pre[i]*1LL, sum + a[i]);
        //printf("%lld %lld\n\n", sum, pre[i]);
    }
    printf("%lld", sum);
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair

#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define br break
#define rem 500009
#define PI 3.1415926535

ll n,m=0,k=0;
 ll A=998244353 ;
 bool bbb;
 ll dis[200005]={0};

 ve <ll> adj[1000005];

ll b[10005]={0};
 bool vis[2000005]={0};
 ll cnt[2000005]={0};
 ve<ll> path;

bool prime[100];
 queue <ll> q;
 queue <ll> p;

 bool isb()
 { b[1]=1;
   q.push(1);
   while(!q.empty())
   {
                          ll x=q.front();
                          q.pop();
                          for(auto u:adj[x])
                          {
                                                 if(b[u]==-1){b[u]=1-b[x];}
                                                 else if(b[u]==b[x]){return false;}
                          }
   }

 }

ll power(ll x,  ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

void SieveOfEratosthenes(ll n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    //bool prime[n+1];
   // memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

}
ll gcd(ll a,ll b)
{
 if(a%b==0)return b;
 else {return gcd(b,a%b);}
}
ll poww(ll x,ll y)
{
                       ll res=1;
                       ll i=0;
                       while(i<y)
                       {
                                              res*=(x);
                                              i++;
                       }
                       return res;
}

ll getsq(ll x)
{
                       ll l=sqrt(x);
                       for( ll i=-2;i<=2;i++)
                       {
                                              if(l+i>=0&&(l+i)*(l+i)==x)
                                              return l;
                       }
                       return -1;
}
 ll inv(ll x)
 {
    return power(x,A-2,A);
 }
bool comp(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
       if(a.first.first<b.first.first)return true;
       else if(a.first.first==b.first.first)
       {
                              if(a.first.second>b.first.second)return true;
                              else{return false;}
       }
       else{return false;}
}

ll maxSubArraySum(ll a[], ll size)
{
   ll max_so_far = a[0];
   ll curr_max = a[0];

   for (ll i = 1; i < size; i++)
   {
        curr_max = max(a[i], curr_max+a[i]);
        max_so_far = max(max_so_far, curr_max);
   }
   return max_so_far;
}
 ll logn(ll x)
 {
                        ll res=0;ll y=x;
                        while((y/3)>0)
                        {
                                               y/=3;
                                               res++;
                        }
                        return res;
 }
 ll powww(ll x)
 {
                        ll res=1;ll y=x;
                        while(y>0)
                        {
                                               y--;
                                               res*=3;
                        }
                        return res;
 }

 void bfs (ll x,bool vis[],ll dis[])
 { vis[x]=true;

   q.push(x);
   while(!q.empty())
   {
   ll s=q.front();q.pop();
     for(auto i=adj[s].begin();i!=adj[s].end();i++)
     {     if(vis[*i]){continue;}
         vis[*i]=true;
         q.push(*i);
         dis[*i]=dis[s]+1;
     }

   }

 }
 ll countFreq(string &pat, string &txt)
{
    ll M = pat.length();
    ll N = txt.length();
    ll res = 0;

    /* A loop to slide pat[] one by one */
    for (ll i = 0; i <= N - M; i++)
    {
        /* For current index i, check for
           pattern match */
        ll j;
        for (j = 0; j < M; j++)
            if (txt[i+j] != pat[j])
                break;

        // if pat[0...M-1] = txt[i, i+1, ...i+M-1]
        if (j == M)
        {
           res++;
           j = 0;
        }
    }
    return res;
}
 bool collinear(ll x1, ll y1, ll x2,
               ll y2, ll x3, ll y3)
{
    // Calculation the area of
    // triangle. We have skipped
    // multiplication with 0.5
    // to avoid floating point
    // computations
    ll a = x1 * (y2 - y3) +
            x2 * (y3 - y1) +
            x3 * (y1 - y2);

    if (a == 0)
       return true;
    else
       return false;
}
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
void solve()
{
                       ll n;cin>>n;
                       ll x=n;
                       ll cnt=0;
                       while(x>0)
                       {
                                              ll y=logn(x);
                                              ll z=powww(y);
                                              if(z<=1){z++;}
                                              x-=z;cnt++;
                       }
                       cout<<cnt;
}

int main()
{ FAST;

    ll t=1;//cin>>t;

    while(t--){
                           solve();
    }
    return 0;
}

#include <iostream>
using namespace std;

__int64 coin[100], i = 0;

//int count(__int64 n) {
//	if (n <= 3) return 1;
//	int j = 1;
//	while (j < i && n > coin[j]) {
//		++j;
//	}
//	if (n == coin[j] || n % coin[j-1] == 0) {
//		return 1;
//	}else {
//		return count(n-coin[j-1]) + 1;
//	}
//}

int main()
{
	coin[0] = 1;

	do{
		++i;
		coin[i] = coin[i-1] * 3;
	}while (coin[i] <= 100000000000000000);

	__int64 n;
	while (cin >> n) {
		for (int j = 1; j < i; ++j) {
			if (n % coin[j] != 0) {
				cout << n / coin[j] + 1 << endl;
				break;
			}
		}

	}
	return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
int main()
{
	ll n,ans,m1=27,m2=9,m3=3,m4=1;
	cin>>n;
	bool Fir=true;
	ans=0;
	while (n)
	{
		if (n%3!=0&&Fir)
		{
			Fir=false;
			ans-=n%3;
		}
		ans+=n%3;
		n/=3;
	}
	ans++;
	cout<<ans<<endl;
}

//E? Nanndatte?
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n;
int main(){
	long long x;
	cin >> x;
	if(x==1)
	{
		puts("1");
	}
	else if(x==2)
	{
		puts("2");
	}
	else if(x==3)
	{
		puts("1");
	}
	else
	{
		cout << x-2 << endl;
	}

}

#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>

using namespace std;

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define sz(a) int((a).size())
#define sqr(x) ((x)*(x))
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define NAME "path"
#define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout);
#define Freopen freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

typedef unsigned int unt;
typedef unsigned long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double geom;

const int INF = 2e9;
const ll INF64 = 3e18;
const ld EPS = 1e-12;
const ld PI = 3.1415926535897932384620;
const ll MD = 925262732;
const ll T = 634521;
const int N = 300101;
const int M = 1010;
const int MAGIC = 4000;

int main() {
    ios_base::sync_with_stdio(0);
    ll n, ans, q = -1;
    cin >> n;
    while (n){
        if (n % 3 != 0 && q == -1)
            q = n % 3;
        ans += n % 3;
        n /= 3;
    }

    cout << ans - q + 1;

    return 0;
}

/*

*/

/* What did you expect before reading my fantastic code ="= ? */

#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <cstring>
#include <string>
#include <utility>

using namespace std;

#define For(i, a, b) for(int i= a; i<= b; i++)
#define ForD(i, a, b) for(int i= a; i>= b; i--)
#define Reset(a, b) memset(a, b, sizeof(a))
#define Enter scanf("\n")

typedef vector <int> VI;
typedef vector <string> VS;
typedef long long ll;
typedef pair<int, int> II;
const int MaxN= 5005;
const int oo= 1000000000;
const ll Base= 1000000007;
typedef int Tarr[MaxN];

int main() {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);

    ll n, Res;
    cin >> n;
    Res= 0;
    int i= 1;
    while (n% i== 0) i*= 3;
    cout << n/ i+ 1;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>

#define MEMV(X, V) (memset(X, V, sizeof(X)))
#define MEM(X) (MEMV(X, 0))
#define MAX 10000000

using namespace std;

int main() {

    long long n;
    cin >> n;

    for(long long i = 3; ; i = i * 3)
    {
        if(i > n)
        {
            cout << 1;
            break;
        }
        else if((n % i) != 0)
        {
            cout << (long long)ceil(n / (double)i);
            break;
        }
    }

    return 0;
}

#include <cstdio>
int main ()
{
    long long n;
    scanf("%d",&n);
    long long i = n;
    if(n%3==0) { printf("1\n"); return 0; }
    while(i%3)
    {
        i+=1;
    }
    printf("%I64d\n",i/3);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vector<(type)>
#define all(c) ((c).begin(),(c).end())
#define I(var) cin>>(var)
#define O(var) cout<<(var)
#define ON(var) cout<<var<<"\n"
#define F(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)

/*##################################################################################*/

/*
int prime[10000000] = {0} ;
void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/

/*
ll fib(int n)
{
  ll a = 0, b = 1, c, i;
  if( n == 0)
    return a;
  for (i = 2; i <= n; i++)
  {
    c = (a + b);
    a = b;
    b = c;
  }
  return b;
}
*/

/*
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
*/

/*
ll findgrouplcm(ll arr[], ll n)
{
    ll ans = arr[0];

    for (ll i = 1; i < n; i++)
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));

    return ans;
}
*/

ll powerwithmod(ll x, unsigned ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

void solve(int n,ll s[],ll p[]);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        unsigned ll n,res;I(n);
        int i = 0 ;
        if(n == 1){
            O("1");
            return 0 ;
        }
        while(powerwithmod(3,i,1000000000000000000) <= n){
            ++i;
        }
        res = powerwithmod(3,i,1000000000000000000);
        if(2*(res/3) == n or (res/3) == n){
            O("1");
        }
        else{
            O((ceil((float)n/(res/3))));
        }
    }
    return 0;
}