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