#include <bits/stdc++.h>
using namespace std;
bool possible(long long mid, long long k, long long n) {
  long long t = k, cnt = 0;
  k = 1;
  while ((mid / k) >= 1) {
    cnt += (mid / k);
    k *= t;
  }
  if (cnt >= n)
    return true;
  else
    return false;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = 1e9, s = 1, e = 1e9;
  while (s <= e) {
    long long mid = (s + e) / 2;
    if (possible(mid, k, n)) {
      ans = mid;
      e = mid - 1;
    } else
      s = mid + 1;
  }
  cout << ans << endl;
}
