#include <bits/stdc++.h>
using namespace std;
void INP();
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  if (0) return;
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  if (0) return;
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
bool check(float v, float n, float k) {
  long long int sum = v;
  long long int x = v;
  while (x) {
    sum += x / k;
    x /= k;
  }
  if (sum >= n)
    return 1;
  else
    return 0;
}
void alpha() {
  long long int n, k;
  cin >> n >> k;
  long long int s = 1, e = n, mid;
  long long int ans;
  while (s <= e) {
    mid = (s + e) / 2;
    if (check(mid, n, k)) {
      e = mid - 1;
    } else {
      s = mid + 1;
    }
  }
  cout << s << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  INP();
  long long int t = 1;
  while (t--) alpha();
  return 0;
}
inline void INP() {}
