4. Let real numbers $a_{1}, a_{2}, \cdots, a_{2011}$ satisfy
$$
\begin{array}{l}
a_{1}=a_{2017}, \\
\left|a_{i}+a_{i+2}-2 a_{i+1}\right| \leqslant 1(i=1,2, \cdots, 2015) . \\
\text { Let } M=\max _{1 \leq i<j \leq 17}\left|a_{i}-a_{j}\right| \text {. Find the maximum value of } M \text { . }
\end{array}
$$
4. Let $\left|a_{i_{0}}-a_{j_{0}}\right|=\max _{1 \leqslant i1008$ when, then
$$
\begin{array}{l}
\left|a_{j_{0}}-a_{i_{0}}\right|=\left|a_{i_{0}}-a_{1}\right|+\left|a_{2017}-a_{j_{0}}\right| \\
\leqslant \frac{\left(i_{0}-1\right)^{2}}{2}+\frac{\left(2017-j_{0}\right)^{2}}{2} \\
\leqslant \frac{\left(2016-j_{0}+i_{0}\right)^{2}}{2} \leqslant \frac{1008^{2}}{2} .
\end{array}
$$

The above shows that $M \leqslant \frac{1008^{2}}{2}$.
Taking $a_{n}=\frac{(1009-n)^{2}}{2}(n=1,2, \cdots, 2017)$, then $a_{1009}-a_{1}=\frac{1008^{2}}{2}$.
In this case, $M=\frac{1008^{2}}{2}$.
Therefore, the maximum value of $M$ is $\frac{1008^{2}}{2}$.