n,m=map(int,input().split()) dp=[0]*5010101 dp[1]=0 dp[2]=1 for i in range(3,n+1): dp[i]=(dp[i-1]+dp[i-2])%m print(dp[n])