#include <bits/stdc++.h>
using namespace std;
bool check(int mid, int k, int n) {
  int lines = 0;
  int curlines;
  int counter = 0;
  while (1) {
    curlines = floor(mid / pow(k, counter));
    if (curlines == 0) return 0;
    lines += curlines;
    if (lines >= n) return 1;
    counter++;
  }
}
int main() {
  int n;
  int k;
  cin >> n >> k;
  int l = 1, r = 10000000010;
  int ans;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (check(mid, k, n)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
