#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool check(long long v) {
  long long sum = 0;
  while (v > 0 && sum < n) {
    sum += v;
    v /= k;
  }
  return (sum >= n);
}
void solve(long long test) {
  cin >> n >> k;
  long long l = 0, r = 1e18;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << (check(l) ? l : r) << "\n";
}
int main() {
  long long test = 1;
  for (long long i = 1; i <= test; i++) solve(i);
}
