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