#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[ ";
  for (auto v : V) os << v << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, set<T> S) {
  os << "{ ";
  for (auto s : S) os << s << " ";
  return os << "}";
}
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R>
ostream& operator<<(ostream& os, map<L, R> M) {
  os << "{ ";
  for (auto m : M) os << "(" << m.F << ":" << m.S << ")";
  return os << "}";
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long const M = 1e9;
bool check(long long v, long long n, long long k) {
  long long s = n;
  long long d = k;
  while (n / k >= 1) {
    s = s + n / k;
    k = k * d;
  }
  return (s >= v);
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long l = 0;
  long long r = M;
  while (r - l > 1) {
    long long mid = (l + r) >> 1;
    if (check(n, mid, k))
      r = mid;
    else
      l = mid;
  }
  cout << r << "\n";
  return 0;
}
