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