#include <bits/stdc++.h>
long int search(long int, long int, int t, long int);
int main() {
  long int n, p, q;
  int k;
  scanf("%ld", &n);
  scanf("%d", &k);
  q = search(1, n, k, n);
  printf("%ld", q);
  return 0;
}
long int search(long int start, long int end1, int t, long int size1) {
  long int mid, s, v, h, sum, l;
  if (end1 - start == 0)
    return end1;
  else {
    mid = (end1 + start) / 2;
    v = mid;
    sum = v;
    while (v / t != 0) {
      sum += v / t;
      v = v / t;
    }
    if (sum >= size1) {
      return search(start, mid, t, size1);
    } else {
      return search(mid + 1, end1, t, size1);
    }
  }
}
