#include <bits/stdc++.h>
int n, k;
bool check(int v) {
  int p, q;
  p = v;
  q = 0;
  while (p > 0) {
    q += p;
    p /= k;
  }
  return q >= n;
}
int main() {
  int l, m, r;
  scanf("%d %d", &n, &k);
  l = 1;
  r = n;
  while (l != r) {
    m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m + 1;
  }
  printf("%d\n", l);
  return 0;
}
