#include <bits/stdc++.h>
using namespace std;
long long n, m;
int main() {
  cin >> n >> m;
  long long ans = 1000000000000000000LL;
  for (long long i = 2; i <= m; i++) {
    if (1ll * i * i > m) i = m;
    int cnt = 0;
    while (m % i == 0) {
      cnt++;
      m /= i;
    }
    if (cnt == 0) continue;
    long long tmp = 0, mul = 1;
    while (mul <= n / i) {
      mul *= i;
      tmp += n / mul;
    }
    ans = min(ans, tmp / cnt);
  }
  cout << ans << endl;
  return 0;
}
