#include <bits/stdc++.h>
using namespace std;
int N, K;
bool check(int v) {
  long long ret = 0;
  while (v) {
    ret += v;
    v /= K;
  }
  return ret >= N;
}
int main() {
  scanf("%d %d", &N, &K);
  int s = 0, e = N, ret = -1;
  while (s <= e) {
    int mid = (s + e) / 2;
    if (check(mid))
      e = mid - 1, ret = mid;
    else
      s = mid + 1;
  }
  printf("%d\n", ret);
}
