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