#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 50;
int n, K;
bool judge(long long y) {
  long long ret = 0;
  while (y > 0) {
    ret += y;
    y /= K;
  }
  return ret >= n;
}
int main() {
  cin >> n >> K;
  long long L = 0, R = INF;
  while (R - L > 1) {
    long long mid = (R + L) >> 1;
    if (judge(mid))
      R = mid;
    else
      L = mid;
  }
  cout << R << endl;
  return 0;
}
