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