#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, p, j;
  cin >> n >> k;
  long long l = 0, r = 1000000000000, mid, ans = 0;
  while (r - l > 1) {
    mid = (r + l) / 2;
    j = mid;
    ans = mid;
    p = k;
    while ((mid / p) > 0) {
      ans += (j / p);
      p *= k;
    }
    if (ans >= n)
      r = j;
    else
      l = j;
  }
  cout << r;
  return 0;
}
