#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5;
long long cmp = 1e16;
const int md = 1e7 + 5;
long long n, k;
bool check(long long c) {
  long long w = 0, d = 1LL;
  long long nd;
  while (w < n) {
    nd = (c / d);
    if (!nd) break;
    w += nd;
    d *= k;
  }
  return w >= n ? 1 : 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  long long st = 0, md, en = 1e18;
  while (st < en) {
    md = st + ((en - st) >> 1LL);
    if (check(md))
      en = md;
    else
      st = md + 1;
  }
  cout << en << "\n";
}
