#include <bits/stdc++.h>
using namespace std;
long long st[32], k;
int n, m;
long long f(long long v) {
  long long sum = 0;
  for (int i = 0; i < m; i++) {
    sum += v / st[i];
  }
  return sum;
}
long long bin_search() {
  long long l = 0, r = (long long)10 * n;
  while (r - l > 1) {
    long long m = (l + r) >> 1;
    if (f(m) >= n) {
      r = m;
    } else {
      l = m;
    }
  }
  return r;
}
int main() {
  cin >> n >> k;
  st[0] = 1;
  m = 1;
  while (st[m - 1] < n) {
    st[m] = st[m - 1] * k;
    m++;
  }
  cout << bin_search() << endl;
  return 0;
}
