#include <bits/stdc++.h>
using namespace std;
const long long MAX = 100000001;
int dx[8] = {1, 0, 0, -1, 1, -1, 1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
int n, k;
bool check(int limit) {
  int sum = 0;
  while (limit) {
    sum += limit;
    limit /= k;
  }
  if (sum >= n)
    return 1;
  else
    return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  int lo = 0, hi = n;
  while (lo < hi) {
    int mid = lo + (hi - lo) / 2;
    if (check(mid))
      hi = mid;
    else
      lo = mid + 1;
  }
  cout << hi;
  return 0;
}
