#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool check(long long x) {
  long long count = 0;
  long long d = 1;
  while (x / d != 0) {
    count += (x / d);
    d = d * k;
    if (count >= n) return 1;
  }
  return 0;
}
int main() {
  scanf("%lld%lld", &n, &k);
  long long l = 0, r = n, mid, ans, i, j;
  while (r >= l) {
    mid = l + (r - l) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
