#include const int INF=1<<30; int main(){ int n,a; std::cin >> n >> a; int ans=0,count=1; while(n>0){ ans+=count; n/=a; count*=2; } std::cout << ans << '\n' ; }