#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 5;
long long a[MAXN];
long long n, k;
bool check(long long x) {
  long long sum = 0;
  while (x) {
    sum += x;
    x /= k;
  }
  return sum >= n;
}
int main() {
  cin >> n >> k;
  long long l = 0, r = n;
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << l + 1 << endl;
}
