#include <bits/stdc++.h>
const int N = 1e6 + 7;
using namespace std;
int arr[N];
long long Can(long long n, long long k) {
  long long i = 0, p = pow(k, i), sum = 0;
  while ((n / p) > 0) {
    sum += (n / p);
    p = pow(k, ++i);
  }
  return sum;
}
int main() {
  {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  };
  long long sz, k;
  cin >> sz >> k;
  long long l = 0, r = sz, ans = -1;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (Can(mid, k) >= sz)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
