#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef string sg;
typedef long lg;
typedef double de;
typedef char ch;
typedef long long ll;
typedef bool bl;
typedef unsigned int ui;
typedef unsigned long long ull;
int main()
{
ll num=0,n,k;
cin>>n>>k;
while(n>=k){
num+=n;
n=(n/k);
}
num+=n;
cout<<num;
return 0;
}