#include <bits/stdc++.h>
using namespace std;
int n, k;
int ans;
inline int f(int n) {
  int rt = 0;
  for (int i = 0; n / pow(k, i) != 0; i++) rt += n / pow(k, i);
  return rt;
}
void bin_search() {
  int s = 1, e = n;
  int m;
  while (s <= e) {
    m = (s + e) / 2;
    if (f(m) >= n) {
      e = m - 1;
      ans = m;
    } else
      s = m + 1;
  }
}
int main() {
  cin >> n >> k;
  bin_search();
  cout << ans << endl;
  return 0;
}
