#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll val(ll v, ll k) {
  ll res = v;
  ll c = k;
  ll d = v / k;
  while (d > 0LL) {
    d = v / k;
    res += d;
    k *= c;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, k;
  cin >> n >> k;
  ll l = min(k, n), h = max(k, n);
  ll v = INT_MAX;
  while (l <= h) {
    ll mid = (l + h) / 2;
    ll res = val(mid, k);
    if (res == n) {
      v = mid;
      break;
    } else if (res < n) {
      l = mid + 1;
    } else if (res > n) {
      v = min(v, mid);
      h = mid - 1;
    }
  }
  cout << v << '\n';
  return 0;
}
