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: x,d,c=2,1,int(n**0.25) y=(x*x+1)%n while d<2 and c:x,y,d,c=(x*x+1)%n,(y**4+2*y*y+2)%n,G(abs(x-y),n),c-1 if d>i&1<1:c[d]=c[d]*c[d|1<>i&1])%2] print((v-(m<2))%Q)