#include <bits/stdc++.h>
using namespace std;
double n, k;
long long f(long long mid) {
  long long index = log(mid) / log(k), ans = 0;
  ans = 0;
  for (int i = 0; i <= index; i++) ans += mid / pow(k, i);
  return ans;
}
long long bs(long long lo, long long hi) {
  long long mid = ((lo + hi) >> 1);
  while (f(lo) < n and f(hi) >= n and hi - lo > 1) {
    f(mid) < n ? lo = mid : hi = mid;
    mid = ((lo + hi) >> 1);
  }
  return hi;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  cout << bs(0, n) << "\n";
  return 0;
}
