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