#include<bits/stdc++.h> using namespace std; int x,k; int main(){ cin>>x>>k; for(int i=1;i<=k;i++){ x+=1; if(x%3==0) x/=3; } cout<<x; return 0; }