N,M = map(int,input().split()) dp = [0,1,2] for i in range(N): ii = i % 3 dp[ii-1 if ii+2>2 else ii+2] = dp[ii-2 if ii+1>2 else ii+1]+dp[ii] print(dp[(N+2)%3]%M)