13. In the sequence $\left\{a_{n}\right\}$, it is known that
$$
a_{1}=2, a_{n+1} a_{n}+a_{n+1}-2 a_{n}=0 \text {. }
$$

For any positive integer $n$, we have
$\sum_{i=1}^{n} a_{i}\left(a_{i}-1\right)<M$ (where $M$ is a constant and an integer).
Find the minimum value of $M$.
Three, 13. From the problem, for $n \in \mathbf{N}_{+}, a_{n} \neq 0$, and
\[
\frac{1}{a_{n+1}}=\frac{1}{2}+\frac{1}{2 a_{n}},
\]
which means
\[
\frac{1}{a_{n+1}}-1=\frac{1}{2}\left(\frac{1}{a_{n}}-1\right).
\]
Given $a_{1}=2$, we have $\frac{1}{a_{1}}-1=-\frac{1}{2}$.
Therefore, the sequence $\left\{\frac{1}{a_{n}}-1\right\}$ is a geometric sequence with the first term $-\frac{1}{2}$ and common ratio $\frac{1}{2}$. Thus,
\[
\frac{1}{a_{n}}-1=-\frac{1}{2} \times\left(\frac{1}{2}\right)^{n-1}=-\left(\frac{1}{2}\right)^{n},
\]
which implies
\[
a_{n}=\frac{2^{n}}{2^{n}-1}.
\]
Hence,
\[
a_{i}\left(a_{i}-1\right)=\frac{2^{i}}{\left(2^{i}-1\right)^{2}}(i=1,2, \cdots, n).
\]
For $i \geqslant 2$, we have
\[
\begin{array}{l}
a_{i}\left(a_{i}-1\right)=\frac{2^{i}}{\left(2^{i}-1\right)^{2}}<\frac{2^{i}}{\left(2^{i}-1\right)\left(2^{i}-2\right)} \\
=\frac{2^{i-1}}{\left(2^{i}-1\right)\left(2^{i-1}-1\right)}=\frac{1}{2^{i-1}-1}-\frac{1}{2^{i}-1} . \\
\text { Therefore, } \sum_{i=1}^{n} a_{i}\left(a_{i}-1\right)=\sum_{i=1}^{n} \frac{2^{i}}{\left(2^{i}-1\right)^{2}} \\
<\frac{2^{1}}{\left(2^{1}-1\right)^{2}}+\sum_{i=2}^{n}\left(\frac{1}{2^{i-1}-1}-\frac{1}{2^{i}-1}\right) \\
=3-\frac{1}{2^{n}-1}<3 . \\
\text { Also, } \sum_{i=1}^{n} a_{i}\left(a_{i}-1\right)=\sum_{i=1}^{n} \frac{2^{i}}{\left(2^{i}-1\right)^{2}} . \\
\geqslant \frac{2^{1}}{\left(2^{1}-1\right)^{2}}=2 .
\end{array}
\]
Therefore, the minimum value of $M$ is 3.