#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;
int n, k;
int get(int u) {
  int res = u;
  while (u) {
    res += u / k;
    u /= k;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n >> k;
  int dau = 1, cuoi = 1000000000;
  while (dau <= cuoi) {
    int mid = (dau + cuoi) >> 1;
    if (get(mid) >= n)
      cuoi = mid - 1;
    else
      dau = mid + 1;
  }
  cout << dau;
  return 0;
}
