#include <bits/stdc++.h>
using namespace std;
long long solve(long long v, long long k) {
  long long tot = v;
  long long tmpk = k;
  while ((v / tmpk) > 0) {
    tot += (v / tmpk);
    tmpk *= k;
  }
  return tot;
}
int main() {
  long long n, k;
  cin >> n >> k;
  ;
  int left = 1, right = n;
  long long ans = -1;
  while (left <= right) {
    int mid = (left + right) >> 1;
    if (solve(mid, k) >= n) {
      ans = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << ans << endl;
}
