3. The real numbers $x_{1}, x_{2}$, and $x_{3}$ are the three roots of the equation $x^{3}-3 x^{2}+2(1-p) x+4=0$, considering their possible multiplicities. Find the smallest value of the expression $\left(x_{1}-1\right)^{2}+\left(x_{2}-1\right)^{2}+\left(x_{3}-1\right)^{2}$ under these conditions. For which $p$ is it realized?
The smallest value 6 is achieved when $p=1$.