#include <bits/stdc++.h>
using namespace std;
int main() {
  double n, q;
  cin >> n >> q;
  int min_val = (int)(((q - 1) * n) / q);
  for (int k = min_val; k <= (int)n; k++) {
    double sum = k;
    double mid_k = k;
    while (mid_k != 0) {
      mid_k = (int)(mid_k / q);
      sum += mid_k;
    }
    if (sum >= n) {
      cout << k << endl;
      return 0;
    }
  }
  return 0;
}
