#include <bits/stdc++.h>
using namespace std;
int n, sum1 = 0, sum2 = 0, k = 0, res = 1, m;
int a[110000], b[110000];
int main() {
  cin >> n >> m;
  k = n;
  res = n;
  sum1 = n % m;
  while (k >= m) {
    k /= m;
    res += k;
    cerr << res << " ";
    sum1 += k % m;
  }
  if ((res + sum1 / m) % m == 0) res += 1;
  cout << res + sum1 / m;
  return 0;
}
