#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  int k;
  cin >> k;
  long long low = 1;
  long long high = 1e9;
  while (low < high) {
    long long v = low + (high - low) / 2;
    long long val = v;
    long long nn = n;
    while (val > 0) {
      nn -= val;
      val /= k;
    }
    if (nn > 0) {
      low = v + 1;
    } else {
      high = v;
    }
  }
  cout << low << endl;
  return 0;
}
