#include <bits/stdc++.h>
using namespace std;
void solve();
void pre();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
bool isgood(long long n, long long k, long long x) {
  long long c = x, v;
  v = k;
  while (x >= v) {
    c += (x / v);
    v *= k;
  }
  return c >= n;
}
inline void solve() {
  long long n, k, l, h, m, ans;
  cin >> n >> k;
  l = 1;
  h = n;
  while (l <= h) {
    m = l + (h - l) / 2;
    if (isgood(n, k, m)) {
      ans = m;
      h = m - 1;
    } else {
      l = m + 1;
    }
  }
  cout << ans << "\n";
}
