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