#include<iostream>
#include<cstdio>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
ll s[1000100];
int main(){
int a,n;
while(scanf("%d %d",&a,&n)){
priority_queue<ll,vector<ll>,greater<ll> > q;
int pos=0;
q.push(a);
int pret=0;
while(!q.empty()){
ll t=q.top();q.pop();
if(pret==t)continue;
pret=t;
s[pos++]=t;
if(pos>n+100)break;
q.push(2*t+1);
q.push(3*t+1);
}
printf("%lld\n",s[n-1]);
}
}
#include<cstdio>
#include<set>
#include<queue>
typedef long long ll;
using namespace std;
ll s[1000100];
int main(){
int a,n;
while(scanf("%d %d",&a,&n)){
priority_queue<ll,vector<ll>,greater<ll> > q;
int pos=0;
q.push(a);
int pret=0;
while(!q.empty()){
ll t=q.top();q.pop();
if(pret==t)continue;
pret=t;
s[pos++]=t;
if(pos>n+100)break;
q.push(2*t+1);
q.push(3*t+1);
}
printf("%lld\n",s[n-1]);
}
}