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