#include <bits/stdc++.h>
using namespace std;

void solve(int n,int k){
    unsigned long long int ans=1,a,b;
    double mul=(double)k/(k-1);
    for(int i=0;i<n-1;i++){
        a=ans/(k-1);
        b=ans%(k-1);
        b*=k;
        if(b%(k-1))b=b/(k-1)+1;
        else b=b/(k-1);
        ans=a*k+b;
    }
    cout<<ans-1<<endl;
}
int main(void){
    int a,b;
    while(cin>>a>>b){
        solve(a,b);
    }
    
}