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