#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, m, ans = 999999999999999999, mn = 123456789000LL;
  cin >> n >> m;
  long long x = n;
  vector<pair<long long, long long> > v;
  long long cnt = 0;
  for (long long i = 2; i <= sqrt(m); i++) {
    if (m % i == 0) {
      cnt = 0;
      while (m % i == 0) {
        cnt++;
        m = m / i;
      }
      v.push_back({i, cnt});
    }
  }
  if (m > 1) {
    mn = 1;
    v.push_back({m, 1});
  }
  for (int i = 0; i < v.size(); i++) {
    long long y = x;
    long long temp = 0;
    while (y) {
      temp += y / v[i].first;
      y = y / v[i].first;
    }
    temp = temp / v[i].second;
    ans = min(temp, ans);
  }
  cout << ans << endl;
}
