#include <bits/stdc++.h>
using namespace std;
int n, k;
long long int l, r, mid, te, kpow;
int main() {
  cin >> n >> k;
  r = n;
  l = 0;
  while (r >= l) {
    mid = (r + l) / 2;
    te = 0;
    kpow = 1;
    while (mid >= kpow) {
      te += mid / kpow;
      kpow *= k;
    }
    if (te > n)
      r = mid;
    else if (te < n)
      l = mid + 1;
    else {
      cout << mid;
      return 0;
    }
    if (r == l && mid == l) break;
  }
  cout << mid;
}
