N, MOD = map(int, input().split()) Z = 5*10**6 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])