#include <bits/stdc++.h>
using namespace std;
int main() {
  long long r, h = 1e9, l = 0, m, v, n, k;
  cin >> n >> k;
  while (h - l > 1) {
    m = (h + l) / 2;
    v = m, r = 0;
    while (v) {
      r += v;
      v /= k;
    }
    (r >= n) ? h = m : l = m;
  }
  cout << h << endl;
}
