//丹阳新区实小路彦
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
long long int p[N];
int main()
{
int k, n;
cin >> k >> n;
p[0] = 1;
for (int i = 1; i <= n; i++)
p[i] = p[i - 1] * k;
int cot = n;
long long int ans = 0;
for (int i = 0; i < 32; i++)
if ((cot >> i)& 1) ans += p[i];
cout << ans << endl;
return 0;
}