N,M=map(int,input().split()) n=N//3 a=1 for i in range(n):a=a*(N-i)//(i+1) print(0if N%3 else a//(2*n+1)%M)