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