#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long Cal(long long x) {
  long long v = 0;
  long long a = 1;
  while (x >= a) {
    v += x / a;
    a *= k;
  }
  return v;
}
int main() {
  int i, j;
  cin >> n >> k;
  long long l = 1, r = n;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (Cal(mid) < n)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
}
