#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, n;
while (cin >> a >> n)
{
int blah[1000050] = {};
int k, k1, k2;
k = k1 = k2 = 1;
blah[k] = a;
while (true)
{
int b1 = 2 * blah[k1] + 1, b2 = 3 * blah[k2] + 1;
if (b1 < b2)
{
blah[++k] = b1;
k1++;
}
else if (b1 > b2)
{
blah[++k] = b2;
k2++;
}
else
{
blah[++k] = b1;
k1++;
k2++;
}
if (blah[n] != 0)
{
cout << blah[n] << endl;
break;
}
}
}
return 0;
}