I am having trouble figuring out an equality on dimensions in the proof below from John Lee's Introduction to Smooth Manifolds.
In the proof, how do we get $\dim T_p M - \dim T_{\Phi(p)}N=\dim T_p S$? I can't figure out why this equality holds despite working on it for a long time now. I would greatly appreciate some help.

The intersection $S\cap U$ is a regular level set of $\Phi$, so the codimension of $S\cap U$ equals the dimension of $N$, by Corollary 5.13 (Submersion Level Set Theorem). In other words, $\dim M - \dim S\cap U = \dim N$. But $\dim S\cap U = \dim S$ because $S\cap U$ is open in $S$ (as $S$ is embedded in $M$ and $U$ is open in $M$), and so $$\dim T_pM - \dim T_{\Phi(p)}N = \dim M - \dim N = \dim S\cap U = \dim S = \dim T_pS.$$