using namespace std;
int main() {
int n; cin >> n; int t=n,m=n,h; //t可换的 h是不够换的 m总瓶数 while(t>=3) //可换的大于3执行 { h=t%3; t/=3; m+=t; t=t+h; } cout << m <<endl;
}