#include <bits/stdc++.h>
using namespace std;
long long i, j, x, y, z, ans, c, d, n, k;
bool fun(long long v) {
  z = 0;
  y = 1;
  while (v) {
    z += v;
    v /= k;
    if (z >= n) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  long long low, high, mid;
  low = 1;
  high = n;
  while (low < high) {
    mid = (low + high) / 2;
    if (fun(mid))
      high = mid;
    else
      low = mid + 1;
  }
  cout << high;
  return 0;
}
