#include <bits/stdc++.h>
using namespace std;
bool isprime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
string itos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
const double PI = acos(-1.0);
static const double EPS = 1e-5;
int N, K;
bool cal(int s) {
  int sum = 0;
  int cnt = 0;
  while (s >= pow(K, cnt)) {
    sum += s / pow(K, cnt);
    cnt++;
  }
  return sum >= N;
}
int main() {
  while (cin >> N >> K) {
    int lb = 0, ub = INT_MAX;
    while (ub - lb > 1) {
      int mid = (lb + ub) / 2;
      if (cal(mid)) {
        ub = mid;
      } else {
        lb = mid;
      }
    }
    cout << ub << endl;
  }
  return 0;
}
