#include <bits/stdc++.h>
using namespace std;
int n, k;
bool valid(int v) {
  long long x = 1, sum = 0;
  while (v / x) {
    sum += v / x;
    x *= k;
  }
  return (sum >= n);
}
int main() {
  scanf("%d%d", &n, &k);
  int lo = 0, mid, hi = n;
  while (lo < hi) {
    mid = lo + (hi - lo) / 2;
    if (!valid(mid))
      lo = mid + 1;
    else
      hi = mid;
  }
  printf("%d\n", lo);
  return 0;
}
