#include <bits/stdc++.h>
int n, k, l, r, mid, t;
int test(int mid) {
  int ans = 0;
  while (mid > 0) {
    ans += mid;
    mid /= k;
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &k);
  l = 1;
  r = n;
  while (l < r) {
    mid = (l + r) / 2;
    t = test(mid);
    if (t < n)
      l = mid + 1;
    else
      r = mid;
  }
  printf("%d\n", l);
  return 0;
}
