#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, t, t1;
  while (~scanf("%d%d", &n, &m)) {
    t = n / m;
    if (n % m)
      t1 = n % m;
    else
      t1 = 0;
    int sum = 0;
    while (t) {
      sum += t;
      t += t1;
      t1 = 0;
      if (t % m) t1 = t % m;
      t = t / m;
    }
    printf("%d\n", n + sum);
  }
  return 0;
}
