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