#include <bits/stdc++.h>
using namespace std;
int main() {
  long double n, k;
  long long c, i, j, k1, min;
  cin >> n >> k;
  min = (long long)(n * ((long double)1 - 1.0 / k));
  long long k2 = (long long)k;
  for (i = min;; i++) {
    k1 = i;
    c = k1;
    while (1) {
      if (k1 / k2 == 0)
        break;
      else
        c += k1 / k2;
      k1 /= k2;
    }
    if (c >= n) break;
  }
  cout << i;
  return 0;
}
