#include <bits/stdc++.h>
using namespace std;
int n, k, sum;
bool ok(int v) {
  sum = 0;
  int l = k;
  int m = 1;
  while (v / m > 0) {
    sum += v / m;
    l = k;
    m *= l;
  }
  if (sum >= n)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n >> k;
  int start = 0;
  int end = n;
  int mid;
  while (start < end) {
    mid = (start + end) / 2;
    if (ok(mid))
      end = mid;
    else
      start = mid + 1;
  }
  cout << start;
}
