#include <iostream>
#define int long long
using namespace std;
long long x,k;//看清范围
signed main(){
cin>>x>>k;
for(int i=1;i<=k;i++){
x=x+1;
if(x%3==0) x=x/3;
if(x==1){
if(k%2==0) cout<<1;
else cout<<2;
return 0;
}
}
cout<<x;
return 0;
}
//50分
肝了好久也是50分,求调!!