#include <bits/stdc++.h>
using namespace std;
int test(int n, int v, int k) {
  int total = v;
  int a = k;
  for (int i = 0; i < v; i++) {
    if (v / k >= 1) {
      total += (v / k);
      k *= a;
    } else {
      if (total >= n)
        return true;
      else
        return false;
    }
  }
  return false;
}
int BBsearch(int high, int low, int mid, int n, int k) {
  if (high <= low) return high;
  mid = (high + low) / 2;
  if (test(n, mid, k) == true) {
    return BBsearch(mid, low, mid, n, k);
  } else {
    return BBsearch(high, mid + 1, mid, n, k);
  }
}
int main() {
  int n, k, high, low, mid;
  cin >> n >> k;
  high = n;
  low = 0;
  mid = 0;
  cout << BBsearch(high, low, mid, n, k) << endl;
}
