#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
  cin.sync_with_stdio(0);
  cin >> n >> k;
  int lo = 1, hi = n;
  while (lo < hi) {
    int mid = lo + hi >> 1;
    long long temp = 1LL * k;
    int cnt = mid;
    while (mid / temp > 0) {
      cnt += mid / temp;
      temp *= k;
    }
    if (cnt < n)
      lo = mid + 1;
    else
      hi = mid;
  }
  cout << hi << endl;
  return 0;
}
