#include <bits/stdc++.h>
using namespace std;
long long k;
long long total(long long x) {
  int sum = 0;
  while (x) {
    sum += x;
    x = x / k;
  }
  return sum;
}
int main() {
  long long int n;
  while (cin >> n >> k) {
    long long end;
    if (n < k)
      cout << n << endl;
    else {
      long long left = 1;
      long long right = n;
      while (left <= right) {
        long long middle = (left + right) / 2;
        long long t = total(middle);
        if (t >= n) {
          right = middle - 1;
          end = middle;
        } else
          left = middle + 1;
      }
      cout << end << endl;
    }
  }
  return 0;
}
