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