R=range I=lambda:map(int,input().split()) T,m=I() M=[m] P=set() def G(a,b): while a:a,b=b%a,a return b def r(n): for j in R(len(M)): while M[j]%n<1:M[j]//=n P.add(n) while M: n=M.pop() if n<99: i=2 while i*i<=n: if n%i<1 and not i in P:r(i) while n%i<1:n//=i i+=1 if n>1:r(n) else: for t in R(99): x,d,c=t,1,0 y=(x*x+1)%n while d<2 and c*c>i&1<1:c[d]=c[d]*c[d|1<>i&1])%2] print((v-(m<2))%Q)