8・20 Let $x_{1}, x_{2}, \cdots, x_{n}$ be a sequence of positive integers, each not greater than $M$, and satisfying
$$x_{k}=\left|x_{k-1}-x_{k-2}\right|, k=3,4, \cdots, n .$$

How many terms can such a sequence have at most?
[Solution] From (1), when $x_{k}=2$, we have $1, m, m-1,1, m-2, \cdots$, thus
$$\begin{array}{l}
l_{m}=3+l_{m-2} . \\
l_{m}=\left\{\begin{array}{ll}
\frac{3 m+1}{2}, & m \text { is odd, } \\
\frac{3 m+2}{2}, & m \text { is even. }
\end{array}\right.
\end{array}$$

For positive integers $m>1$, due to $m-1, m, 1, m-1, \cdots$, the first term is $m-1$, the maximum term is $m$, and the number of terms in the sequence of positive integers satisfying (1) is
$$\sigma_{m}=\left\{\begin{array}{ll}
\frac{3 m+3}{2}, & m>1 \text { and is odd, } \\
\frac{3 m+2}{2}, & m \text { is even. }
\end{array}\right.$$

Supplementing $\sigma_{1}=2$, we can prove by induction that the maximum number of terms in the sequence of positive integers with the maximum term $m$ and satisfying (1) is $\sigma_{m}$.

In fact, when $m=1,2,3$, it is easy to verify that the proposition holds. Assume that the proposition holds for $m \leqslant l(l \geqslant 3)$. Take any sequence $x_{1}, x_{2}, \cdots, x_{n}$ with the maximum term $l+1$ and satisfying condition (1). If $x_{1}=l, x_{2}=l+1$, from the above discussion, we know $n=\sigma_{l+1}$. In other cases, by the induction hypothesis, it is easy to know
$$n \leqslant 3+\sigma_{l-1}=\sigma_{l+1}$$

Thus, the proposition also holds for $m=l+1$.
In summary, the maximum number of terms sought is
$$\sigma_{M}=\left\{\begin{array}{ll}
2, & M=1 ; \\
\frac{3 M+3}{2}, & M \text { is greater than } 1 \text { and is odd; } \\
\frac{3 M+2}{2}, & M \text { is even. }
\end{array}\right.$$