\(y=1-cos^2x+cosx+2=-cos^2x+cosx+2+1\)
\(y=\left(cosx+1\right)\left(2-cosx\right)+1\ge1\)
\(\Rightarrow m=1\) khi \(cosx=-1\)
\(y=-cos^2x+cosx+3=-\left(cosx-\frac{1}{2}\right)^2+\frac{13}{4}\le\frac{13}{4}\)
\(\Rightarrow M=\frac{13}{4}\) khi \(cosx=\frac{1}{2}\)