#include <bits/stdc++.h>
using namespace std;
long long int pot(long long int k, long long int i) {
  long long int total = 1;
  for (long long int j = 0; j < i; j++) {
    total *= k;
  }
  return total;
}
long long int summm(long long int v, long long int k) {
  long long int soma = 0;
  long long int i = 0;
  while (v / pot(k, i) != 0) {
    soma += v / pot(k, i);
    i++;
  }
  return soma;
}
long long int buscaa(long long int n, long long int k) {
  long long int left = 1;
  long long int right = n;
  while (left <= right) {
    long long int mid = left + (right - left) / 2;
    long long int soma = summm(mid, k);
    if (soma == n) {
      return mid;
    } else if (soma > n) {
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
}
int main() {
  long long int n, k;
  cin >> n >> k;
  long long int a;
  a = buscaa(n, k);
  cout << a << endl;
  return 0;
}
