#include <bits/stdc++.h>
using namespace std;
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
long long int mod = 1000000007;
long long int po(long long int x, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n % 2 == 1) res = ((res) * (x));
    x = (x * x);
    n = n / 2;
  }
  return res;
}
long long int ceil(long long int x, long long int y) {
  if (x % y == 0)
    return x / y;
  else
    return (x / y) + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  long long int l = 1, r = n;
  long long int mid;
  long long int cnt = 0;
  for (long long int i = 0; i < 30; i++) {
    if (n >= po(k, i)) {
      cnt++;
    } else {
      cnt++;
      break;
    }
  }
  while (l <= r) {
    mid = (l + r) / 2;
    long long int ans = 0;
    for (long long int i = 0; i < cnt; i++) {
      ans += mid / po(k, i);
    }
    if (ans >= n)
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l;
}
