II. (40 points) Let $p$ be a prime number, and the sequence $\left\{a_{n}\right\}$ satisfies $a_{0}=0, a_{1}=1$, and for any non-negative integer $n$,
$$
a_{n+2}=2 a_{n+1}-p a_{n} \text {. }
$$

If -1 is a term in the sequence $\left\{a_{n}\right\}$, find all possible values of $p$.
The only $p$ that satisfies the condition is $p=5$.
It is easy to see that when $p=5$, $a_{3}=-1$.
Next, we prove that it is the only solution.
Assume $a_{m}=-1\left(m \in \mathbf{N}_{+}\right)$.
Clearly, $p \neq 2$, otherwise, from $a_{n+2}=2 a_{n+1}-2 a_{n}$, we know that for $n \geqslant 2$, $a_{n}$ is always even.
Thus, the sequence cannot contain -1.
Therefore, $(2, p)=1$.
Taking the recurrence relation $a_{n+2}=2 a_{n+1}-p a_{n}$ modulo $p$ gives $a_{n+2} \equiv 2 a_{n+1}(\bmod p)$,

which means the sequence $\left\{a_{n}\right\}$ is a geometric sequence modulo $p$, and we have
$$
a_{n+1} \equiv 2^{n} a_{1}(\bmod p) \text {. }
$$

In particular, we have
$$
-1 \equiv a_{m} \equiv 2^{m-1} a_{1} \equiv 2^{m-1}(\bmod p) .
$$

Taking $a_{n+2}=2 a_{n+1}-p a_{n}$ modulo $p-1$ gives
$$
\begin{array}{l}
a_{n+2} \equiv 2 a_{n+1}-a_{n}(\bmod (p-1)) \\
\Rightarrow a_{n+2}-a_{n+1} \equiv a_{n+1}-a_{n}(\bmod (p-1)),
\end{array}
$$

which means the sequence $\left\{a_{n}\right\}$ is an arithmetic sequence modulo $p-1$, and we have
$$
\begin{array}{l}
a_{n+1} \equiv(n+1)\left(a_{1}-a_{0}\right)+a_{0} \\
\equiv n+1(\bmod (p-1)) .
\end{array}
$$

In particular, we have
$$
-1 \equiv a_{m} \equiv m(\bmod (p-1)),
$$

which implies $m+1 \equiv 0(\bmod (p-1))$.
By $(2, p)=1$ and Fermat's Little Theorem, we get
$$
2^{p-1} \equiv 1(\bmod p) \text {. }
$$

Combining with equation (1), we get
$$
1 \equiv 2^{p-1} \equiv 2^{m+1} \equiv 4 \times 2^{m-1} \equiv-4(\bmod p) \text {. }
$$

Thus, $5 \equiv 0(\bmod p)$.
Therefore, $p=5$ is the only solution that satisfies the requirement.