#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int r, l, mid;
  r = n;
  l = 1;
  int sum, os, ans;
  while (l <= r) {
    os = 0;
    sum = 0;
    mid = (l + r) / 2;
    while ((mid / pow(k, os)) > 0) {
      sum += mid / pow(k, os);
      ++os;
    }
    if (sum >= n) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
}
