#include <bits/stdc++.h>
using namespace std;
int a[100000 + 10], b[100000 + 10], dp[100000 + 10];
long long int fun(long long int mid, long long int k) {
  long long int sum = mid;
  while (mid != 0) {
    sum += mid / k;
    mid = mid / k;
  }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long int k, n, i;
  cin >> n >> k;
  long long int lo = 1;
  long long int hi = max(n, k);
  long long int ans;
  while (lo <= hi) {
    long long int mid = (lo + hi) / 2;
    long long int res = fun(mid, k);
    if (res >= n) {
      hi = mid - 1;
      ans = mid;
    } else
      lo = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
