#include <bits/stdc++.h>
using namespace std;
long long int n, k;
long long int result(int v) {
  long long int sum = v;
  long long int term = v;
  while (term) {
    term /= k;
    sum += term;
  }
  return sum;
}
int main() {
  cin >> n;
  cin >> k;
  long long int v = n * (k - 1);
  v /= k;
  if (n == 1) {
    cout << 1;
    return 0;
  }
  for (int i = 0; i < 12; ++i) {
    if (result(v + i) >= n) {
      cout << v + i;
      break;
    }
  }
  return 0;
}
