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