#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, p, q, sum = 0;
  cin >> n >> m;
  p = n;
  while (n != 1) {
    if (n % m == 0) {
      n = n / m;
      sum = sum + n;
    } else {
      q = n % m;
      n = n / m;
      sum = sum + n;
      n = n + q;
      if (n < m) {
        n = 1;
      }
    }
  }
  cout << sum + p << endl;
  return 0;
}
