#include <bits/stdc++.h>
using namespace std;
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
void file() {}
unsigned long long gcd(unsigned long long x, unsigned long long y) {
  if (y == 0) {
    return x;
  }
  return gcd(y, x % y);
}
void bitmask(string s) {
  int n = s.size();
  for (int i = 0; i < pow(2, n); i++) {
    string z;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        z += s[j];
      }
    }
    cout << z << "\n";
  }
}
bool com(const pair<int, int>& x, const pair<int, int>& y) {
  if (x.first == y.first) {
    return (x.second > y.second);
  }
  return (x.first < y.first);
}
bool ca(long long x, long long n, long long k) {
  for (long long i = 0; i < 50; i++) {
    long long z = ceil(pow(k, i));
    long long r = x / z;
    n -= r;
    if (n <= 0) {
      return 1;
    }
  }
  return 0;
}
int main() {
  file();
  fast();
  long long n, k;
  cin >> n >> k;
  long long r = 1, l = 10e9, ans = 0, mid = 0;
  while (r <= l) {
    mid = (r + l) / 2;
    if (ca(mid, n, k)) {
      ans = mid;
      l = mid - 1;
    } else {
      r = mid + 1;
    }
  }
  cout << ans << "\n";
  return 0;
}
