#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int l = 1, r = n;
  while (l != r) {
    long long int x, mid;
    x = mid = int((l + r) / 2);
    long long int sum = 0;
    while (x != 0) {
      sum += x;
      x = int(x / k);
    }
    if (sum >= n)
      r = mid;
    else
      l = mid + 1;
  }
  cout << l;
  return 0;
}
