Let $f: M \rightarrow \mathbb{R}$ be a differentiable function that is regular everywhere on the compact manifold with boundary $M$. Show that $f$ assumes its extrema on the boundary.
I know that regular means that the rank of the Jacobian matrix is $1$. Which means that $df_p \neq 0$ for all $p$. Also, since the manifold is compact and $f$ is continuous, it must have a max and a min. But why is it on the boundary? How can I use the fact that $df_p \neq 0$ for all $p$?