#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    int lb = 1;
    int ub = n;
    int ans;
    while (lb <= ub) {
      long long mid = lb + ub >> 1;
      long long temp = mid;
      long long t2 = k;
      while (temp < n) {
        temp += mid / t2;
        t2 *= k;
        if (t2 > mid) break;
      }
      if (temp >= n) {
        ans = mid;
        ub = mid - 1;
      } else
        lb = mid + 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
