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