#include <bits/stdc++.h>
int p, n, k;
using namespace std;
long long int sum(int v) {
  long long int res = v, i;
  for (i = 1; i <= p; i = i + 1) {
    res = res + (v / ((long long int)pow(k, i)));
  }
  return res;
}
int main() {
  cin >> n >> k;
  p = (log(n) / log(k));
  int i;
  int low = 1;
  int high = n;
  int ares = n;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (sum(mid) == n) {
      ares = mid;
      break;
    } else if (sum(mid) > n) {
      if (mid < ares) {
        ares = mid;
      }
      high = mid - 1;
    } else if (sum(mid) < n) {
      low = mid + 1;
    }
  }
  cout << ares << endl;
}
