#include<iostream>
#include<cmath>
using namespace std;
int qmi(int k, int an)
{
int res = 1;
for(; an > 0; an = an >> 1)
{
if(an & 1) res = res * k;
k = k * k;
}
return res;
}
int main()
{
int k, n;
cin >> k >> n;
int r = 1, an = 0;
int res = 0;
while(n)
{
if(n & 1) res = res + qmi(k, an);
an++;
n = n >> 1;
}
cout << res << endl;
return 0;
}