#include <bits/stdc++.h>
using namespace std;
int const sz = 2 * 1e5;
int const oo = 1e9;
bool comp(int i, int j) { return i < j; }
long long num[1000000], kk[101];
void fill(int n, int m) {
  long long arr[4] = {0, 1, 2, 3};
  int l = 0;
  num[0] = 1;
  num[1] = 2;
  num[2] = 3;
  for (int i = 3; i < n; i++) {
    arr[(l % 3) + 1] = ((arr[1] + arr[2] + arr[3]) % m) + 1;
    num[i] = arr[(l++ % 3) + 1];
    if (num[i] < 101) kk[num[i]]++;
  }
}
long long check(long long m, int k) {
  long long a = 1;
  long long sum = 0;
  while (m / a > 0) {
    sum = sum + (m / a);
    a *= k;
  }
  return sum;
}
void solve() {
  long long n, k;
  cin >> n >> k;
  long long l = 0, r = n;
  while (l < r - 1) {
    long long m = (l + r) / 2;
    if (check(m, k) >= n)
      r = m;
    else
      l = m;
  }
  cout << r;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
