#include<bits/stdc++.h>
using namespace std;
long long x,k,ts,zzz=0;
int main(){
cin>>x>>k;
ts=x;
while(ts!=2){
ts+=1;
if(ts%3==0){
ts/=3;
}
zzz++;
if(zzz==k){
break;
}
}
if(ts!=2){
cout<<ts;
}
else{
if((k-zzz)%2==1){
cout<<"1";
}
else{
cout<<"2";
}
}
return 0;
}