#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, v, mid, l, h, p, s, ans;
  cin >> n >> k;
  l = 1;
  h = n;
  while (l <= h) {
    mid = (l + h) / 2;
    s = 0;
    p = 1;
    while (mid / p > 0) {
      s = s + mid / p;
      p = p * k;
    }
    if (s >= n) {
      ans = mid;
      h = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans;
  return 0;
}
