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