#include <bits/stdc++.h>
using namespace std;
long long int S(int n, int k) {
  long long int s = 0;
  long long int x = n;
  long long int p = k;
  while (x != 0) {
    s += x;
    x = n / p;
    p = p * k;
  }
  return s;
}
int main() {
  long long int n, k;
  cin >> n >> k;
  float N = n, K = k;
  float x = N * (1 - (1 / K));
  int i;
  for (i = x; i >= 0; i++) {
    if (S(i, k) >= n) {
      cout << i;
      break;
    }
  }
  return 0;
}
