#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool okay(long long v) {
  long long x = 1;
  long long w = 0;
  while (v / x > 0) {
    w += v / x;
    x *= k;
  }
  return w >= n;
}
int main() {
  ios::sync_with_stdio(0);
  while (cin >> n >> k) {
    long long lo = 1, hi = 1e12;
    while (lo < hi) {
      long long mid = (lo + hi) / 2;
      if (!okay(mid))
        lo = mid + 1;
      else
        hi = mid;
    }
    cout << lo << endl;
  }
  return 0;
}
