#include <bits/stdc++.h>
int k;
int write(int v) {
  long long n, p;
  for (n = v, p = k; v / p; p *= k) n += v / p;
  return (int)n;
}
int main(int argc, char *argv[]) {
  int n, l, u, m;
  scanf("%d %d", &n, &k);
  l = 1, u = n;
  do {
    m = (l + u) / 2;
    if (write(m) >= n && write(m - 1) < n) {
      printf("%d\n", m);
      return 0;
    }
    if (write(m) >= n)
      u = m - 1;
    else
      l = m + 1;
  } while (1);
  return 0;
}
