#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  int max = n;
  int min = 1;
  while (max - 1 != min) {
    int mid = (max + min) / 2;
    int c = mid;
    double i = k, q = 1;
    while (floor(mid / i)) {
      c += floor(mid / i);
      i *= k;
    }
    if (c > n) {
      max = mid;
    } else if (c < n) {
      min = mid;
    } else {
      cout << mid;
      return 0;
    }
  }
  cout << max;
}
