#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, k;
bool good(ll m) {
  ll lines = 0;
  while (m) {
    lines += m;
    m /= k;
  }
  return lines >= n;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  ll l = 0, r = 1e10;
  while (r > l + 1) {
    ll m = (l + r) / 2;
    if (good(m))
      r = m;
    else
      l = m;
  }
  cout << r << "\n";
}
