#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int total = n, temp = n, a = 0;
  while (temp >= m) {
    a = temp % m;
    temp = (temp) / m;
    total = total + temp;
    temp = temp + a;
  }
  cout << total << endl;
}
