#include <bits/stdc++.h>
using namespace std;
int main() {
  int l, r, n, k, m, v, sum;
  cin >> n >> k;
  r = n;
  l = 0;
  while (l < r) {
    m = v = (l + r) >> 1;
    for (sum = 0; v; v /= k) {
      sum = sum + v;
    }
    if (sum >= n) {
      r = m;
    } else {
      l = m + 1;
    }
  }
  cout << l << endl;
  return 0;
}
