#include <bits/stdc++.h>
using namespace std;
long long int n, k, ans;
long long int check(long long int v) {
  long long int sum = 0;
  while (v > 0) {
    sum += v;
    v /= k;
  }
  return sum;
}
void BS(long long int l, long long int r) {
  while (l <= r) {
    long long int mid = (l + (r - l) / 2);
    long long int sum = check(mid);
    if (sum >= n) {
      r = mid - 1;
      ans = min(ans, mid);
    } else
      l = mid + 1;
  }
}
void solve() {
  cin >> n >> k;
  ans = n;
  long long int l, r;
  l = 1;
  r = n;
  BS(l, r);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
