#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  solve();
  return 0;
}
void solve() {
  int n, k;
  cin >> n >> k;
  long long left = 1, right = n, sum = 0, s = 0;
  while (left < right) {
    int mid = left + (right - left) / 2;
    s = mid;
    sum = s;
    while (s > 0) {
      s /= k;
      sum += s;
    }
    if (sum < n) {
      left = mid + 1;
    } else {
      right = mid;
    }
  }
  cout << right;
}
