#include<iostream>
#include<cmath>

using namespace std;

using ll = long long;

int main() {
    ll N,k,now=0;
    cin >> N >> k;
    ll step;
    ll mod, div;
    ll tmp;
    for(;;){
        N--;
        if(N==0)break;

        div = now/k;
        step = div + 1;
        tmp = step*k;
        mod = now%k;
        while(now+step >= tmp){
            step += (now+step-tmp)/k + 1;
            tmp = step*k;
        }
        now += step;
    }
    cout << now << endl;
    return 0;
}

