#include <bits/stdc++.h>
using namespace std;
long long int M = 1e9 + 7;
int sum_digit(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}
int reverse_num(int n) {
  int tmp = n, ans = 0, r;
  while (tmp > 0) {
    r = tmp % 10;
    ans = ans * 10 + r;
    tmp /= 10;
  }
  return ans;
}
long long int factorial(long long int n) {
  long long int i, ans = 1;
  for (i = n; i > 1; i--) {
    ans *= i;
  }
  return ans;
}
long long int gcd(long long int num1, long long int num2) {
  long long int a, b, r;
  a = num1;
  b = num2;
  r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
long long int lcm(long long int num1, long long int num2) {
  return (num1 * num2) / gcd(num1, num2);
}
bool prime(long long int n) {
  if (n < 2) return false;
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool vowel(char ch) {
  ch = tolower(ch);
  if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
    return true;
  return false;
}
long long int n, k;
bool ok(int m) {
  long long int v = k, sum = m;
  while (m / v) {
    sum += m / v;
    v *= k;
  }
  return sum >= n;
}
void solve() {
  cin >> n >> k;
  long long int l = 1, r = n;
  for (int i = 0; i < 100; i++) {
    int m = (l + r) / 2;
    if (ok(m))
      r = m;
    else
      l = m;
  }
  cout << r << endl;
}
int main() {
  solve();
  return 0;
}
