N,M=map(int,input().split()) F1,F2=0,1 for i in range(2,N): Fn=F1+F2 F1=F2 F2=Fn print(Fn%M)