#include <bits/stdc++.h>
using namespace std;
bool is(long long n, long long k, long long target) {
  long long ans = 0;
  int i = 2;
  long long l = k;
  long long x = n;
  while (n > 0) {
    ans += n;
    n = x / k;
    k = pow(l, i);
    i++;
  }
  if (ans >= target) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long l = 1, r = n;
  long long ans = n;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (is(mid, k, n)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
