#include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
using namespace std;

int main(){
	ll n,k; cin >>n>>k;
	ll ans=0;
	for(int i=0;i<n-1;i++){
		ans=ans%(k-1)+1+ans/(k-1)*k;
	}
	cout << ans << endl;
}
