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