#include <iostream>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("errors.txt", "w", stderr);
#endif
double n ; int k ;
cin >> n >> k ;
if(n <= k) {
cout << n ; return 0 ;
}
int i = n * (1 - (1.0/k)) ;
bool flag =1 ;
int v=0 ;
while(flag) {
int p =0 ;
double x = 1 ;
double sum =0 ;
while(i >= x) {
sum += (i / x) ;
if(sum >= n) {
v = i ;
flag =0 ;
}
x *= k ;
}
i++;
}
cout << v ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmludCBtYWluKCkKewojaWZuZGVmIE9OTElORV9KVURHRQogICAgZnJlb3BlbigiaW5wdXQudHh0IiwgInIiLCBzdGRpbik7CiAgICBmcmVvcGVuKCJvdXRwdXQudHh0IiwgInciLCBzdGRvdXQpOwogICAgZnJlb3BlbigiZXJyb3JzLnR4dCIsICJ3Iiwgc3RkZXJyKTsKI2VuZGlmCiAgICBkb3VibGUgbiA7IGludCBrIDsKICAgIGNpbiA+PiBuID4+IGsgOwogICAgaWYobiA8PSBrKSB7CiAgICAgICAgY291dCA8PCBuIDsgcmV0dXJuIDAgOwogICAgfQogICAgaW50IGkgPSBuICogKDEgLSAoMS4wL2spKSA7CiAgICBib29sIGZsYWcgPTEgOwogICAgaW50IHY9MCA7CiAgICB3aGlsZShmbGFnKSB7CiAgICAgICAgaW50IHAgPTAgOwogICAgICAgIGRvdWJsZSB4ID0gMSA7CiAgICAgICAgZG91YmxlIHN1bSA9MCA7CiAgICAgICAgd2hpbGUoaSA+PSB4KSB7CiAgICAgICAgICAgIHN1bSArPSAoaSAvIHgpIDsKICAgICAgICAgICAgaWYoc3VtID49IG4pIHsKICAgICAgICAgICAgICAgIHYgPSBpIDsKICAgICAgICAgICAgICAgIGZsYWcgPTAgOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHggKj0gayA7CiAgICAgICAgfQogICAgICAgIGkrKzsKICAgIH0KICAgIGNvdXQgPDwgdiA7Cn0K