#include <bits/stdc++.h>
using namespace std;
int n;
int k;
bool judge(int v);
int main() {
  while (cin >> n >> k) {
    int x = 1;
    int y = n;
    int v;
    while (x < y) {
      v = (x + y) / 2;
      if (judge(v))
        y = v;
      else
        x = v + 1;
    }
    cout << x << endl;
  }
  return 0;
}
bool judge(int v) {
  long long sum;
  long long x;
  sum = 0;
  x = 1;
  while (v / x) {
    sum += v / x;
    x = x * k;
  }
  if (sum >= n)
    return 1;
  else
    return 0;
}
