Suppose $M$ and $N$ are smooth manifolds and $S \subset M \times N$ is an immersed submanifold. Let $\pi_M$ and $\pi_N$ denote the projections from $M \times N$ onto $M$ and $N$ respectively.
I am trying to show that if $\pi_M|_S$ is a diffeomorphism from $S$ onto $M$ then $S$ is the graph of a smooth map $f:M\to N$.
The theorem states that if these conditions hold, we can choose $f=\pi_N \circ (\pi_M|_S)^{-1}$.
This means that $S=\{(x,y):x\in M, y=\pi_N \circ (\pi_M|_S)^{-1}(x)\}$.
I cannot figure out how to show that $S$ is the graph of this function. The $N$ component is clear from the definition of $f$ but how can we ensure that the $M$ component of $S$ is the entire $M$? I would greatly appreciate some help.