N,M=map(int,input().split()) A,B,C=0,1,1 for i in range(N-1): A=B B=C C=(A+B)%M print(A%M)