#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, temp, i, count = 0;
  cin >> n >> m;
  temp = m;
  while (n) {
    n--;
    m--;
    if (!m) {
      m = temp;
      n++;
    }
    count++;
  }
  cout << count;
}
