#include <bits/stdc++.h>
using namespace std;
long long n, k, v, l, r, mij, num, s, s1, num1;
int main() {
  cin >> n >> k;
  l = 1;
  r = n * n;
  v = -1;
  while (l <= r) {
    mij = l + (r - l) / 2;
    s = 0;
    num = 1;
    while (num <= mij) {
      s = s + mij / num;
      num = num * k;
    }
    if (s >= n) {
      s1 = 0;
      num1 = 1;
      while (num1 <= mij - 1) {
        s1 = s1 + (mij - 1) / num1;
        num1 = num1 * k;
      }
      if (s1 < n || mij == l) {
        v = mij;
        r = -1;
      } else
        r = mij - 1;
    } else
      l = mij + 1;
  }
  cout << v;
  return 0;
}
