#include <bits/stdc++.h>
const long long INFLL = 4e18;
const int INFINT = 2e9;
using namespace std;
int n, k;
bool check(int num) {
  int ret = num;
  while (num && ret < n) {
    ret += num / k;
    num /= k;
  }
  return ret >= n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int lo = 0, hi = 1000000000, ans;
  cin >> n >> k;
  for (int i = 0; i < 100; i++) {
    int mid = lo + (hi - lo) / 2;
    if (check(mid)) {
      hi = mid - 1;
      ans = mid;
    } else
      lo = mid + 1;
  }
  cout << ans;
}
