#include <bits/stdc++.h>
using namespace std;
int64_t power(int k, int i) {
  if (i == 0) return 1;
  int64_t po = k;
  for (int j = 1; j < i; ++j) po *= k;
  return po;
}
int main() {
  int n, k, v;
  cin >> n >> k;
  int lo = 1, hi = n;
  while (lo < hi) {
    int v = lo + (hi - lo) / 2, temp_n = n;
    for (int i = 0;; i++) {
      int64_t x = power(k, i);
      temp_n -= 1ll * v / x;
      if (temp_n <= 0) {
        hi = v;
        break;
      } else if (x > v) {
        lo = v + 1;
        break;
      }
    }
  }
  cout << lo;
}
