#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ld = long double;
const int N = 51;
const lli MOD = 998244353;
int lol(int a, int b) {
  if (a < b) {
    return 0;
  }
  return a / b + lol(a / b, b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r) / 2;
    if (lol(mid, k) + mid >= n) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  cout << l << endl;
}
