#include <bits/stdc++.h>
using namespace std;
int n, k;
double K[35];
double f(int tv) {
  int p = 0;
  double S = 0;
  while (true) {
    int Y = tv / K[p++];
    if (Y == 0) break;
    S += Y;
  }
  return S;
}
bool g(int tv) { return (f(tv) >= (double)n); }
int main() {
  scanf("%d%d", &n, &k);
  K[0] = 1;
  for (int Z = 1; Z < 35; Z++) K[Z] = K[Z - 1] * k;
  int lv = 0, rv = 1000000001;
  while (lv < rv) {
    if (lv == rv - 1) break;
    int mid = (lv + rv) / 2;
    bool M = g(mid);
    if (M)
      rv = mid;
    else
      lv = mid;
  }
  printf("%d", g(lv) ? lv : rv);
  return 0;
}
