#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, x;
  while (cin >> n >> k) {
    long long sum = 0;
    x = n * (k - 1) / k - 10;
    if (x <= 0) {
      x = 1;
    }
    long long c = x;
    sum = x;
    while (sum < n) {
      c /= k;
      sum += c;
      if (sum >= n) {
        break;
      }
      if (c / k == 0 && sum < n) {
        x++;
        c = x;
        sum = c;
      }
    }
    cout << x << endl;
  }
  return 0;
}
