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