#include "bits/stdc++.h"

using namespace std;

typedef long long lli;
typedef long double ld;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;

#define endl '\n'
#define fore(i,a,b) for(lli i = a; i < b; i++)
#define all(s) begin(s), end(s)
#define sz(s) lli(s.size())
#define f first
#define s second
#define pb push_back
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int const MAXN = 1e7 + 5;
int N[MAXN +5];

void f(lli x){

    if(N[N[x]] > MAXN) return;
    N[N[x]] = 3*x;
    if(N[N[x]- 1] == 0)  N[N[x]- 1] = N[N[x]] - 1;
    if(N[N[x]- 2] == 0)  N[N[x]- 2] = N[N[x]] - 2;
}

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

    N[1] = 2;
    N[2] = 3;
    N[3] = 6;
    
    fore(i,3,n){
        if(N[i] != 0) f(i);
    }

    cout << N[n]<< endl;
   

    
}



