#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e17;
int n, k;
long long ans;
int main() {
  scanf("%d %d", &n, &k);
  long long l = 0, r = inf;
  while (r - l > 1) {
    long long mid = (l + r) >> 1;
    long long cur = 1, sum = 0;
    while (sum < n && cur <= mid) {
      sum += mid / cur;
      cur *= k;
    }
    if (sum >= n) {
      ans = mid;
      r = mid;
    } else {
      l = mid;
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
