#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a, b, c, d, e, f, l, r, sum = 0;
  cin >> n >> k;
  l = 1;
  r = n;
  while (l < r) {
    sum = 0;
    long long mid;
    a = k;
    mid = (l + r) / 2;
    sum += mid;
    while ((mid / a) > 0) {
      sum += (mid / a);
      a *= k;
    }
    if (sum >= n)
      r = mid;
    else
      l = mid + 1;
  }
  cout << l << endl;
  return 0;
}
