#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int total = n;
  int i, div, mod;
  while (n >= m) {
    div = (n / m);
    total = total + div;
    mod = (n % m);
    n = (div + mod);
  }
  printf("%d", total);
  return 0;
}
