#include <bits/stdc++.h>
using namespace std;
long long bin_search(long long s, long long e, long long num, long long k) {
  while (s < e) {
    long long mid = (s + (e - s) / 2);
    long long sum = 0, j = mid;
    while (j) sum += j, j /= k;
    if (sum < num)
      s = mid + 1;
    else
      e = mid;
  }
  return e;
}
int main() {
  long long n, k;
  while (cin >> n >> k) {
    cout << bin_search(1, n, n, k) << endl;
  }
  return 0;
}
