#include <bits/stdc++.h>
using namespace std;
int code(int v, int k) {
  int total = v;
  int mult = k;
  while (v / mult > 0) {
    total += v / mult;
    mult *= k;
  }
  return total;
}
int main() {
  int n, k, v;
  cin >> n;
  cin >> k;
  double sum = ((double)k / (double)(k - 1));
  if ((int)(n / sum) == (n / sum)) {
    v = n / sum;
  } else {
    v = (n / sum) + 1;
  }
  while (code(v, k) < n) {
    v++;
  }
  cout << v;
  return 0;
}
