#include <bits/stdc++.h>
using namespace std;
int n, K;
bool check(int X) {
  int p = 1, theta, cur = 0;
  while (1) {
    cur += X / p;
    if (X / p == 0) break;
    p *= K;
    if (cur >= n) return true;
  }
  return false;
}
int main() {
  cin >> n >> K;
  if (K == 1) {
    puts("1");
    return 0;
  }
  int st = 1, en = n, mid, ans;
  while (st <= en) {
    mid = (st + en) / 2;
    if (check(mid)) {
      ans = mid;
      en = mid - 1;
    } else
      st = mid + 1;
  }
  cout << ans << endl;
}
