def jc(n):  # 求阶乘
    ans = 1
    for i in range(1, n + 1):
        ans *= i
    return ans


num = list(map(int, input().split(" ")))
n = num[0]
a = num[1]
k = 0
nj = jc(n)
while True:
    ak = pow(a, k)
    ak1 = pow(a, k + 1)
    if nj % ak == 0 and nj % ak1 != 0:
        break
    else:
        k = k + 1
print(k)