#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long i = 0, j = n, ans = INT_MAX;
  while (i <= j) {
    long long mid = (i + j) / 2;
    long long temp = n, itr = 0;
    while (temp > 0 && (floor((double)mid / pow(k, itr))) > 0) {
      temp = temp - (floor((double)mid / pow(k, itr)));
      itr++;
    }
    if (temp > 0) {
      i = mid + 1;
    } else {
      ans = min(mid, ans);
      j = mid - 1;
    }
  }
  cout << ans << endl;
}
