#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long N = 1e6 + 5;
const long long mod = 1e+9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
long long n, k;
long long ch(long long first) {
  long long ans = first;
  while (first) {
    first /= k;
    ans += first;
  }
  return (ans >= n);
}
void bs() {
  long long l = 1;
  long long r = 1e9;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (ch(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << (r + 1) << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed;
  cout << setprecision(10);
  ;
  cin >> n >> k;
  bs();
}
