n,m = map(int,input().split()) memo0 = 0 memo1 = 1 memo2 = 1 for i in range(n-1): memo0, memo1 = memo1, memo2 memo2 = (memo0+memo1)%m print(memo0)