#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int lo = 0, hi = n, mid;
  while (hi - lo > 1) {
    mid = (lo + hi) / 2;
    int t = 0, f = mid;
    while (f >= 1) {
      t += f;
      f = f / k;
    }
    if (t < n) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  cout << hi;
}
