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