#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX / 2;
int get(int v, int k) {
  int temp = v;
  int ans = 0;
  while (temp) {
    ans += temp;
    temp /= k;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  int lo = 0;
  int hi = n * 2;
  while (lo < hi) {
    int mid = (lo + hi) >> 1;
    if (get(mid, k) >= n) {
      hi = mid;
    } else
      lo = mid + 1;
  }
  cout << lo << endl;
  return 0;
}
