#include <bits/stdc++.h>
using namespace std;
int k;
int p;
int calc(const int v, const int k) {
  int c = v;
  int k_p = k;
  if (p >= 1) c += v / k_p;
  for (int i = 2; i <= p; ++i) {
    k_p *= k;
    c += v / k_p;
  }
  return c;
}
int main() {
  int n;
  cin >> n;
  cin >> k;
  if (k > n) {
    cout << n << endl;
    return 0;
  }
  p = log(n) / log(k);
  int l = k;
  int h = n;
  while (l != h) {
    int v = (l + h) / 2;
    int c = calc(v, k);
    if (c > n) {
      h = v;
    } else if (c < n) {
      l = v + 1;
    } else {
      cout << v << endl;
      return 0;
    }
  }
  cout << h << endl;
  return 0;
}
