#include <iostream>
using namespace std;
typedef unsigned long long ll;

ll N,K;

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