#include <bits/stdc++.h>
using namespace std;
long long int check(long long int n, long long int k, long long int l) {
  long long int a = 0;
  if (n / k == 0) {
    return 0;
  } else {
    a = n / k;
    k = k * l;
    return a + check(n, k, l);
  }
}
int main() {
  long long int n, k, o, first, last, cur, mincur = 1, minval = 999999999,
                                           tempcur, i;
  cin >> n >> k;
  if (k >= n) {
    cout << n;
    return 0;
  }
  first = 1;
  last = n;
  while (last - first > 1) {
    cur = (first + last) / 2;
    o = cur + check(cur, k, k);
    if (o >= n) {
      minval = o;
      mincur = cur;
      last = mincur;
    } else {
      first = cur;
    }
  }
  cout << mincur;
  return 0;
}
