#include <bits/stdc++.h>
using namespace std;
int dir1[8][2] = {1, 2, 2, 1, 2, -1, 1, -2, -1, 2, -2, 1, -1, -2, -2, -1};
int dir2[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};
int dir3[8][2] = {1, 0, 0, 1, -1, 0, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1};
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
bool Isleap(int year) {
  if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) return true;
  return false;
}
bool isPrime(int x) {
  if (x == 1)
    return false;
  else if (x == 2)
    return true;
  for (int i = 2; i <= sqrt(x * 1.0); ++i) {
    if (x % i == 0) return false;
  }
  return true;
}
int sqr(int x) { return x * x; }
bool check(long long n, long long v, int k) {
  long long ans = 0;
  long long temp = 1;
  while (v / temp > 0) {
    ans += v / temp;
    temp *= k;
  }
  return (ans >= n);
}
int main() {
  int n, k;
  while (~scanf("%d %d", &n, &k)) {
    long long v = -1;
    long long l = 1, r = (long long)n * k;
    while (l <= r) {
      long long mid = (l + r) >> 1;
      if (check(n, mid, k)) {
        v = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    printf("%I64d\n", v);
  }
  return 0;
}
