#include <bits/stdc++.h>
using namespace std;
int n, k;
int judge(int);
int main() {
  cin >> n >> k;
  int l = 1;
  int r = n;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (judge(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
}
int judge(int temp) {
  int sum = temp;
  while (temp) {
    sum += (temp / k);
    temp /= k;
  }
  if (sum >= n)
    return 1;
  else
    return 0;
}
