#include <bits/stdc++.h>
using namespace std;
int n, k;
long long sumar(int v) {
  long long sum = 0;
  long long pot = 1;
  while (pot <= v) {
    sum += v / pot;
    pot = pot * k;
  }
  return sum;
}
int main() {
  int u, v, w;
  cin >> n >> k;
  int begin = 0, end = 1000000000, mid;
  while (begin <= end) {
    mid = (begin + end) / 2;
    if (sumar(mid) < n) {
      begin = mid + 1;
    } else {
      end = mid - 1;
    }
  }
  printf("%d\n", begin);
  return 0;
}
