#include <bits/stdc++.h>
using namespace std;
bool compute(int n, int v, int k) {
  int sum = 0;
  long long _k = 1;
  int v_int = v;
  while (v_int != 0) {
    v_int = v / _k;
    sum += v_int;
    _k *= k;
  }
  if (sum >= n) {
    return true;
  } else {
    return false;
  }
}
void evaluate(istream& r, ostream& w) {
  int n = 0;
  int k = 0;
  r >> n;
  r >> k;
  int start = 1;
  int end = n;
  int middle = 0;
  while (end > start) {
    middle = (start + end) / 2;
    if (compute(n, middle, k)) {
      end = middle;
    } else {
      start = middle + 1;
    }
  }
  cout << start << endl;
}
int main() {
  evaluate(cin, cout);
  return 0;
}
