#include <bits/stdc++.h>
using namespace std;
const long long int INF = 2e18;
void null() {
  long long int n, k, x;
  cin >> n >> k;
  long long int v = n - (n / k) - 1;
  long long int ans = 0;
  while (ans < n) {
    v++;
    x = v;
    ans = 0;
    while (x) {
      ans += x;
      x = x / k;
    }
  }
  cout << v;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  clock_t start, end;
  start = clock();
  cout << fixed << setprecision(11);
  while (t--) {
    null();
  }
  end = clock();
  double time_taken = double(end - start) / double(CLOCKS_PER_SEC);
}
