#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, l, r, z;
  cin >> n >> k;
  for (l = 1, r = 1000000000, z = 0; z < 100; z++) {
    int m = (l + r) / 2;
    for (i = m, j = 0; i > 0; j += i, i /= k)
      ;
    if (j >= n)
      r = m;
    else
      l = m;
  }
  for (i = l, j = 0; i > 0; j += i, i /= k)
    ;
  if (j >= n)
    cout << l;
  else
    cout << r;
  return 0;
}
