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