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