#include <bits/stdc++.h>
using namespace std;
long long int BinaryExponentiation(long long int base, long long int power) {
  long long int res = 1;
  while (power > 0) {
    if (power & 1) {
      res *= base;
      power--;
    } else {
      power /= 2;
      base = base * base;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int low = 1, high = n, mid;
    long long int ans = n, sum = 0, i = 0, x;
    while (low <= high) {
      mid = low + (high - low) / 2;
      sum = 0;
      i = 0;
      x = (mid / pow(k, i));
      sum += x;
      i++;
      while (x > 0) {
        x = (mid / BinaryExponentiation(k, i));
        sum += x;
        i++;
      }
      if (sum >= n) {
        ans = min(ans, mid);
        high = mid - 1;
      } else
        low = mid + 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
