#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, ns, x(5), s(0), p(0);
  bool good(0);
  cin >> n >> k;
  int i = 1, j = n;
  while (i <= j) {
    ns = (i + j) / 2;
    s = ns;
    p = 1;
    while (x != 0) {
      s += ns / pow(k, p);
      if (ns / pow(k, p) == 0) {
        break;
      }
      p++;
      x++;
    }
    if (s < n) {
      i = ns + 1;
    } else {
      j = ns - 1;
    }
  }
  cout << i << endl;
  return 0;
}
