#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, ans, n1, ans1;
  cin >> n;
  cin >> m;
  ans = n;
  n1 = n;
  ans1 = 0;
  while (n != 0) {
    ans1 += n % m;
    n /= m;
    ans += n;
  }
  ans += ans1 / m;
  if (ans % m == 0) ans++;
  cout << ans << endl;
}
