#include <bits/stdc++.h>
using namespace std;
template <class T>
void miz(T &a, T b) {
  if (b < a) a = b;
}
template <class T>
void maz(T &a, T b) {
  if (b > a) a = b;
}
template <class T>
void clear(T &x) {
  T t;
  x.swap(t);
}
template <class T>
T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
unsigned HASH(const char *p) {
  unsigned r = 0;
  while (*p) r = r * 257 + 1 + *p++;
  return r;
}
int ROUND(double x) { return x >= 0 ? x + 0.5 : x - 0.5; }
long long f(long long v, int k) {
  long long m = 1, ret = 0;
  while (m <= v) {
    ret += v / m;
    m *= k;
  }
  return ret;
}
int main() {
  int n, k, _l, _r, _m;
  cin >> n >> k;
  _l = 1;
  _r = n;
  while (_l <= _r) {
    _m = ((_l + _r) >> 1);
    if (f(_m, k) >= n)
      _r = _m - 1;
    else
      _l = _m + 1;
  }
  cout << _l << endl;
  return 0;
}
