#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; ull x,k; int main() { scanf("%llu%llu",&x,&k); while(k--) { x++; if(x%3==0) { x/=3; } if(x==1&&k%3==0) { break; } } printf("%llu",x); return 0; }