#include <bits/stdc++.h>
int main(void) {
  int a, b, c, x, z, n, m, ans;
  scanf("%d %d", &n, &m);
  a = n / m;
  b = n % m;
  z = a;
  x = z + b;
  c = 0;
  while (x >= m) {
    a = x / m;
    b = x % m;
    c = c + a;
    x = a + b;
  }
  ans = c + z + n;
  printf("%d", ans);
  return 0;
}
