#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long low = 1, high = n;
  long long ans = 100000000000;
  while (low <= high) {
    long long mid = (low + high) / 2;
    long long cnt = mid, m = k, x;
    while (1) {
      x = mid / m;
      m *= k;
      cnt += x;
      if (!x) break;
    }
    if (cnt == n) {
      ans = mid;
      break;
    }
    if (cnt > n)
      ans = min(ans, mid), high = mid - 1;
    else
      low = mid + 1;
  }
  cout << ans;
  return 0;
}
