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