II. (40 points) Let $p$ be a prime number, and the sequence $\left\{a_{n}\right\}(n \geqslant 0)$ satisfies $a_{0}=0, a_{1}=1$, and for any non-negative integer $n$, $a_{n+2}=2 a_{n+1}-p a_{n}$. If -1 is a term in the sequence $\left\{a_{n}\right\}$, find all possible values of $p$.

保留了原文的换行和格式。
The only solution that satisfies the problem is $p=5$.
It is easy to see that when $p=5$, $a_{3}=-1$.
Below, we prove that this is the only solution that satisfies the conditions.
Assume $a_{m}=-1\left(m \in \mathbf{Z}_{+}\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. Therefore, the sequence cannot contain -1. Thus, $(2, p)=1$.

For the recurrence relation $a_{n+2}=2 a_{n+1}-p a_{n}$, taking both sides modulo $p$, we get $a_{n+1} \equiv 2^{n} a_{1}(\bmod p)$.
In particular,
$$
-1 \equiv a_{m}=2^{m-1} a_{1} \equiv 2^{m-1}(\bmod p) .
$$

For $a_{n+2}=2 a_{n+1}-p a_{n}$, taking both sides modulo $p-1$, we get
$$
\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 $\left\{a_{n}\right\}$ is an arithmetic sequence modulo $p-1$, so
$$
\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, $-1 \equiv a_{m} \equiv m(\bmod p-1)$, which means $m+1 \equiv 0(\bmod p-1)$.

By $(2, p)=1$ and Fermat's Little Theorem, we know
$$
2^{p-1} \equiv 1(\bmod p) \text {. }
$$

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

which implies $5 \equiv 0(\bmod p)$.
Therefore, the only solution that satisfies the problem is $p=5$.