#include <bits/stdc++.h>
using namespace std;
int n, k;
int find() {
  int floor = 1;
  int lines = n;
  int mid = (lines + floor) / 2;
  int min = n;
  int cur, tea;
  long long cycle;
  while (floor <= lines) {
    cur = 0;
    cycle = 1;
    do {
      tea = mid / cycle;
      cur += tea;
      cycle *= k;
    } while (tea != 0);
    if (cur >= n) {
      lines = mid - 1;
      if (mid < min) min = mid;
    } else {
      floor = mid + 1;
    }
    mid = (lines + floor) / 2;
  }
  return min;
}
int main() {
  scanf("%d %d", &n, &k);
  cout << find() << endl;
}
