#include <bits/stdc++.h>
using namespace std;
long long n, k;
bool good(long long m) {
  long long a = m;
  long long sum = 0;
  while (a > 0) {
    sum += a;
    a /= k;
  }
  if (sum >= n) return true;
  return false;
}
long long f() {
  long long l = 1, r = 1e18;
  long long ans = 1;
  while (l <= r) {
    long long mid = r - (r - l) / 2;
    if (good(mid)) {
      ans = mid, r = mid - 1;
    } else
      l = mid + 1;
  }
  return ans;
}
long long toint(const string &s) {
  stringstream ss;
  ss << s;
  long long x;
  ss >> x;
  return x;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  cout << f();
  return 0;
}
