//Java版代码
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int a = scanner.nextInt();
        int[] factors_n = new int[n + 1];
        int[] factors_a = new int[a + 1];
        for (int i = 2; i <= n; i++) {
            getPrime(factors_n, i);
        }
        getPrime(factors_a, a);
        int ans = Integer.MAX_VALUE;
        for (int i = 2; i <= a; i++) {
            if (factors_a[i] != 0 && factors_n[i] / factors_a[i] < ans) {
                ans = factors_n[i] / factors_a[i];
            }
        }
        System.out.println(ans);
    }
    private static void getPrime(int[] factors, int n) {
        for (int i = 2; i <= Math.sqrt(n); i++) {
            while (n % i == 0) {
                factors[i]++;
                n /= i;
            }
            if (n < i) {
                break;
            }
        }
        if (n > 2) {
            factors[n]++;
        }
    }
}
#Python版代码
from math import factorial
n, a = map(int, input().split())
n = factorial(n)
k = 1
while n % a ** k != 0 or n % a ** (k + 1) == 0:k += 1
print(k)