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