#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  int k;
  cin >> n >> k;
  long l = 1, r = n;
  while (l < r) {
    long m = l + (r - l) / 2;
    long s = 0, v = m;
    while (v != 0) {
      s += v;
      v /= k;
    }
    if (s >= n)
      r = m;
    else
      l = m + 1;
  }
  cout << l << endl;
  return 0;
}
