#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long v = n * (k - 1);
  v = v / k;
  if (v == 0) {
    v++;
  }
  int c = 0;
  while (c == 0) {
    int t = (v / k);
    int s = v;
    while (t != 0) {
      s += t;
      t = (t / k);
    }
    if (s >= n) {
      c = 1;
    } else {
      v++;
    }
  }
  cout << v << endl;
}
