The answer is 23.
The given problem is equivalent to finding the minimum value of
m=2−(a22+1a1+a32+1a2+⋯+a12+1an)=(a1−a22+1a1)+(a2−a32+1a2)+⋯+(an−a12+1an)=a22+1a1a22+a32+1a2a32+⋯+a12+1ana12.
Since ai2+1≥2ai, we have
m≤2a1a2+a2a3+⋯+ana1.
Our result follows from the following well-known fact:
f(a1,⋯,an)=(a1+⋯+an)2−4(a1a2+a2a3+⋯+ana1)≥01◯
for integers n≥4 and nonnegative real numbers a1,a2,⋯,an.
To prove this fact, we use induction on n. For n=4, 1◯ becomes
f(a1,a2,a3,a4)=(a1+a2+a3+a4)2−4(a1a2+a2a3+a3a4+a4a1)=(a1+a2+a3+a4)2−4(a1+a3)(a2+a4),
which is nonnegative by the AM-GM inequality.
Assume that 1◯ is true for n=k for some integer k≥4.
Consider the case when n=k+1. By (cyclic) symmetry in 1◯, we may assume that ak+1=min{a1,a2,…,ak+1}. By the induction hypothesis, it suffices to show that
D=f(a1,…,ak,ak+1)−f(a1,…,ak−1,ak+ak+1)≥0.
Note that
4D=−(a1a2+⋯+akak+1+ak+1a1)+[a1a2+⋯+ak−1(ak+ak+1)+(ak+ak+1)a1]=ak−1ak+1+aka1−akak+1=ak−1ak+1+(a1−ak+1)ak≥0,
completing our proof.
From the above result, we can get
≤==21(a1a2+a2a3+⋯+ana1)81(a1+a2+⋯+an)281×2221,
therefore
a22+1a1a22+a32+1a2a32+⋯+a12+1ana12≤21,
that is m≥23. When a1=a2=1 and a3=⋯=an=0, m=23 holds.