#include <bits/stdc++.h>
using namespace std;
const long long int mod = (long long int)(998244353);
long long int test = 1;
vector<long long int> read(int n) {
  vector<long long int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  return v;
}
long long int n, k;
bool check(long long int mid) {
  long long int ans = 0;
  long long int m = 1;
  long long int cnt = k;
  while ((mid / m) != 0) {
    ans += mid / m;
    m *= cnt;
  }
  return ans >= n;
}
long long int BS() {
  long long int low = 0, high = 1e10;
  long long int ans = 1e10;
  while (low < high) {
    long long int mid = low + (high - low) / 2;
    if (check(mid)) {
      ans = mid;
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}
void solve() {
  long long int i, j, m, cnt = 0, ans = 0, sum = 0;
  cin >> n >> k;
  ans = BS();
  cout << ans << "\n";
  test++;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int i = 1;
  solve();
  return 0;
}
