#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long l = 0, r = n;
  long long v = 0;
  while (l != r) {
    v = (l + r) / 2;
    long long tmp = 0;
    long long p = v;
    while (p) {
      tmp += p;
      p /= k;
    }
    if (tmp >= n)
      r = v;
    else
      l = v + 1;
  }
  cout << l;
  return 0;
}
