#include <bits/stdc++.h>
using namespace std;
inline string Next() {
  string S;
  cin >> S;
  return S;
}
inline string NextLine() {
  string S;
  getline(cin, S);
  return S;
}
inline int NextInt() {
  int n;
  scanf("%d", &n);
  return n;
}
inline long long NextLong() {
  long long n;
  scanf("%lld", &n);
  return n;
}
inline double NextDouble() {
  double n;
  scanf("%lf", &n);
  return n;
}
bool Check(int n, int k, int v) {
  if (v == 53) {
    int b = 0;
  }
  long long s = 0, t = 1;
  while (t <= v) {
    s += v / t;
    t *= k;
  }
  return (s >= n);
}
int main() {
  int n = NextInt();
  int k = NextInt();
  int l = 1, r = n, res = n;
  while (l <= r) {
    int m = (l + r) >> 1;
    if (Check(n, k, m)) {
      res = m;
      r = m - 1;
    } else
      l = m + 1;
  }
  cout << res;
  return 0;
}
