Set $x(0)=x_0$ and $x(T)=x_T$, with $x_0,x_T\in[m,M]$. I will first allow for excursions outside of this interval, and then later add the constraint that $m\leq x(t)\leq M$ for all $0\leq t\leq T$.

Minimize 
$$I=\int_0^TL(x,\dot{x})\,dt\;\;\text{with}\;\;L=(\dot{x}+x)^2$$ 
by solving the Euler-Lagrange equation,
$$\frac{\partial L}{d x}=\frac{d}{dt}\frac{\partial L}{\partial \dot{x}}.$$
The solution is
$$x(t)=a e^t+be^{-t},\;\;a=\frac{e^T x_T-x_0}{e^{2 T}-1},\;\;b= \frac{e^{2T} x_0-e^T x_T}{e^{2 T}-1}.$$
The resulting integral is
$$I=(\coth T-1) \left(x_0-e^T x_T\right)^2.$$
We still need to minimize this by varying $x_0$ and $x_T$ in the interval $[m,M]$, at fixed $T$. I assume $M>0$.

We need to consider several cases:

**A:** If $m\leq 0$, we can just take $x_0=0=x_T$ and reach the minimal $I_{\rm min}=0$.

**B:** If $m>0$ and $T\leq\ln(M/m)\equiv T^\ast$ we can take $x_0=me^T$, $x_T=m$ to reach the minimal $I_{\rm min}=0$.

**C:** If $m>0$ and $T>T^\ast$ the minimum is reached at the end points of the interval, $x_0=M$, $x_T=m$, with $I_{\rm min}=(\coth T-1) \left(me^T -M\right)^2$. In the limit $T\rightarrow\infty$ this tends to $I_{\rm min}\rightarrow 2m^2$.

---

Now I add the constraint that $x(t)$ should be in the interval $[m,M]$ for all $0\leq t\leq T$. Cases A and B still apply. Case C no longer applies, because that trajectory drops below $m$ and then returns back up. I don't yet have a satisfactory proof, but believe the minimum is given by:

**C':** If If $m>0$ and $T>T^\ast$ we take
$$x(t)=\begin{cases}
Me^{-t}&\text{for}\;\;0\leq t<T^\ast\\
m&\text{for}\;T^\ast+\epsilon\leq t\leq T
\end{cases}
$$
and allow the velocity $\dot{x}(t)$ to drop to zero smoothly in the infinitesimal interval $(T^\ast,T^\ast+\epsilon)$. In the limit $\epsilon\rightarrow 0$ this has no effect on $I$, which stays at 
$$I_{\rm min}=(T-T^\ast)m^2.$$

---

**Lower bound on $I$**

Irrespective of the search for an optimal trajectory, it might be helpful to note a rigorous lower bound on $I$:

$$I=\int_0^T (\dot{x}+x)^2\,dt=\int_{0}^T(\dot{x}^2+x^2)\,dt+x_T^2-x_0^2$$
$$\qquad\geq\int_{0}^T x^2\,dt+x_T^2-x_0^2\geq (T-\tau)m^2,\;\;\text{with}\;\;\tau=(M/m)^2-1.$$
This time $\tau$ is well above $T^\ast=\log(M/m)$, so my estimate $I_{\rm min}=(T-T^\ast)m^2$ leaves room for improvement, as indicated by Pietro Majer.