#include <bits/stdc++.h>
using namespace std;
inline bool pos(long long v, long long k, long long n) {
  long long p = 1, s = 0, x;
  while (1) {
    x = v / p;
    if (x == 0) break;
    s += x;
    p *= k;
  }
  return s >= n;
}
int main() {
  long long k, n, ans, lo = 0, hi = 1e17, mid, p;
  cin >> n >> k;
  while (lo + 1 < hi) {
    mid = (hi + lo) >> 1;
    p = pos(mid, k, n);
    if (!p)
      lo = mid;
    else {
      ans = mid;
      hi = mid;
    }
  }
  cout << ans << endl;
}
