Z = 5 * 10**6 + 1 N, MOD = map(int, input().split()) F = [0] * Z F[1] = 0 F[2] = 1 for i in range(3, Z): F[i] = (F[i-1] + F[i-2]) % MOD print(F[N])