#include <bits/stdc++.h>
using namespace std;
int v, k;
bool check(int i) {
  int x = i, y = i, j = 1;
  long long num = 0;
  while (x) {
    num += x;
    x = y / pow(k, j);
    j++;
  }
  if (num >= v)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d", &v, &k);
  int left = 1, right = 1e9;
  int mid;
  while (left <= right) {
    mid = (left + right) / 2;
    if (check(mid)) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  cout << left << endl;
  return 0;
}
