#include using namespace std; typedef long long ll; ll n, k; ll solve(ll x){ if(x<=k) return x-1; ll y=solve(x-(x+k-1)/k); return y/(k-1)*k+1+y%(k-1); } int main() { cin>>n>>k; cout<