#include <bits/stdc++.h>
using namespace std;
long long N, K;
bool possible(long long v) {
  long long lines = 0, _k = 1;
  while (v / _k > 0) {
    lines += v / _k;
    _k *= K;
  }
  return lines >= N;
}
int binary(long long lo, long long hi) {
  long long mid;
  while (lo + 1 != hi) {
    mid = (lo + hi) / 2;
    if (possible(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  while (!possible(lo)) ++lo;
  return (int)lo;
}
int main(void) {
  scanf("%d%d", &N, &K);
  printf("%d\n", binary(0, 1000000010));
  return 42 - 42;
}
