#include<bits/stdc++.h> using namespace std; int main() { int n,k,s=0; cin>>n>>k; while(n>0) { s+=n; n/=k; } cout<<s; return 0; }