#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

ifstream input("MAXNUM.inp");
ofstream output("MAXNUM.out");

struct num
{
	int a;
	int count;
};

int search(int n, int p, int count)
{
	int res = 0;
	for (int i = 1; i <= n; i++)
	{
		int t = i;

		while (t % p == 0)
		{
			res++;
			t /= p;
		}
	}
	return (res / count);
}


int main()
{
	int n, p, index = 2, temp;
	int res = INT32_MAX;
	input >> n >> p;
	vector <num> a;
	while (p != 1)
	{
		if (p % index == 0)
		{
			if (a.size() == 0 || a.back().a != index)
			{
				a.push_back(num{ index, 1 });
			}
			else if (a.back().a == index)
			{
				a.back().count++;
			}
			p /= index;
		}
		else
		{
			index++;
		}
	}
	for (int i = 0; i < a.size(); i++)
	{
		temp = search(n, a[i].a, a[i].count);
		if (temp < res)
		{
			res = temp;
		}
	}

	output << res;
	return 0;
}