#include <bits/stdc++.h>
using namespace std;
long long n, k, ans = 1e18;
bool ok(long long x) {
  long long m = 1, sum = 0;
  while (x / m > 0) {
    sum += x / m;
    m *= k;
  }
  return sum >= n;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  long long st = 0, en = 1e9;
  while (st <= en) {
    long long mid = (st + en) / 2;
    if (ok(mid)) {
      ans = mid;
      en = mid - 1;
    } else
      st = mid + 1;
  }
  cout << ans;
  return 0;
}
