#include <bits/stdc++.h>
using namespace std;
int n, k;
bool ok(int a, int b) {
  int ans = a, p = b;
  while (a / p > 0) {
    ans += a / p;
    p *= b;
  }
  if (ans >= n)
    return 1;
  else
    return 0;
}
int main() {
  cin >> n >> k;
  int r = n, l = 1;
  while (r - l > 1) {
    int mid = (r + l) / 2;
    if (ok(mid, k) == 0)
      l = mid;
    else
      r = mid;
  }
  cout << r;
  return 0;
}
