#include <bits/stdc++.h>
using namespace std;
int k;
int f(int v) {
  int res = 0;
  unsigned long long int tmp = 1;
  while (v / tmp) {
    res += v / tmp;
    tmp *= k;
  }
  return (res);
}
int main() {
  int n;
  cin >> n >> k;
  int a = 0;
  int b = n;
  while (a < b) {
    int m = (a + b) / 2;
    int tmp = f(m);
    if (tmp < n)
      a = m + 1;
    else
      b = m;
  }
  cout << b;
  return (0);
}
