#include <bits/stdc++.h>
using namespace std;
int n, k;
int chk(int v) {
  int s = 0, cnt = 0;
  while (1) {
    s += int(v / pow(k, cnt));
    cnt++;
    if (s >= n)
      return 1;
    else if ((v / pow(k, cnt)) < 1)
      return 0;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k;
  int lo = 1, hi = n, ans;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (chk(mid)) {
      ans = mid;
      hi = mid - 1;
    } else
      lo = mid + 1;
  }
  cout << ans;
}
