#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, a, k, b, c, n, t, m, p, q, d, e, f, y, g, z, h, r, l, x,
      o;
  long double aa, bb, ee, dd, ff, kk, gg;
  vector<long long int> v, s, vv;
  map<long long int, vector<long long int> > me;
  map<long long int, long long int> sa, ta, pa, ma;
  priority_queue<long long int, vector<long long int>, greater<long long int> >
      aq, tq, pq;
  string st, et, ft, pt, ct;
  deque<long long int> de, pe, ne;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  l = 1;
  r = n * 2;
  while (l < r) {
    c = (l + r) / 2;
    a = c;
    d = 0;
    while (c) {
      d = d + c;
      c = c / k;
    }
    if (d < n)
      l = a + 1;
    else
      r = a;
  }
  cout << l << endl;
}
