#include <bits/stdc++.h>
bool x[10000001] = {false};
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) {
    return (b);
  } else {
    return (gcd(b % a, a));
  }
}
vector<long long int> pri;
long long int fast(long long int n, long long int a) {
  if (n == 0)
    return (1);
  else if (n == 1)
    return (a);
  else {
    long long int r = fast(n / 2, a) % 1000000007;
    if (n % 2 == 0)
      return (((r % 1000000007) * (r % 1000000007)) % 1000000007);
    else
      return (((((r % 1000000007) * a) % 1000000007) * r)) % 1000000007;
  }
}
long long int check(long long int x, long long int k) {
  long long int ans = x;
  while (x / k > 0) {
    ans += (x / k);
    x /= k;
  }
  return (ans);
}
int main() {
  long long int n, k;
  scanf("%lld%lld", &n, &k);
  long long int lo = 1, hi = 1e18;
  long long int mid, ans;
  while (lo <= hi) {
    mid = (lo + hi) / 2;
    if (check(mid, k) >= n) {
      ans = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << ans;
}
