4. For which values of the real parameter $m$ does the equation

$$
x^{2}-(m+1) x+2 m-4=0
$$

have real solutions, and at the same time, the sum of their squares is the smallest possible?
4. Let $x_{1}$ and $x_{2}$ be the solutions of the given equation. From Vieta's formulas, we have $x_{1}+x_{2}=m+1$ and $x_{1} x_{2}=2 m-4$. Therefore, it follows that

$$
x_{1}^{2}+x_{2}^{2}=\left(x_{1}+x_{2}\right)^{2}-2 x_{1} x_{2}=(m+1)^{2}-2(2 m-4)=m^{2}-2 m+9
$$

The function $m^{2}-2 m+9$ has a minimum (vertex) at the point $m=\frac{-(-2)}{2}=1$ (and then $x_{1}^{2}+x_{2}^{2}=8$). Since for $m=1$ the equation in the problem statement is $x^{2}-2 x-2=0$ and its solutions are indeed real (the discriminant is positive: $(-2)^{2}+4 \cdot 2=12>0$), the solution to the problem is $m=1$.