\(y=sinx-cosx+1=\sqrt{2}sin\left(x-\frac{\pi}{4}\right)+1\)
Do \(-1\le sin\left(x-\frac{\pi}{4}\right)\le1\)
\(\Rightarrow1-\sqrt{2}\le y\le1+\sqrt{2}\)
\(\Rightarrow\left\{{}\begin{matrix}M=1+\sqrt{2}\\m=1-\sqrt{2}\end{matrix}\right.\) \(\Rightarrow M-m=2\sqrt{2}\)