#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  while (cin >> n >> m) {
    long long a[100100], b[101000], p, x, i, j, mm, l, r, cc = 0, pp, y, m1,
                                                          qq = 0;
    l = 1;
    r = n + 1;
    while (l <= r) {
      x = (l + r) / 2;
      mm = 1;
      pp = 0;
      while (1) {
        if (x / mm == 0) {
          break;
        }
        pp += x / mm;
        mm *= m;
      }
      if (n > pp)
        l = x + 1;
      else
        r = x - 1;
    }
    cout << l << "\n";
  }
  return 0;
}
