#include <bits/stdc++.h>
using namespace std;
const long long N = 1000005;
long long check(long long v, long long k) {
  long long count = 0, temp = 1;
  while (v >= temp) {
    count += v / temp;
    temp *= k;
  }
  return count;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  long long l = 0, r = n, mid = 0;
  while (l + 1 < r) {
    mid = (l + r) / 2;
    if (check(mid, k) >= n) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << "\n";
}
