#include <bits/stdc++.h>
using namespace std;
int n, k;
int cheak(int x) {
  int sum = x;
  while (x) {
    sum += x / k;
    x /= k;
  }
  if (sum >= n) return 1;
  return 0;
}
int main() {
  scanf("%d%d", &n, &k);
  int head = 1, tail = n;
  while (head <= tail) {
    int mid = (head + tail) / 2;
    if (cheak(mid))
      tail = mid - 1;
    else
      head = mid + 1;
  }
  printf("%d\n", head);
  return 0;
}
