Invertible differentiable map from $\mathbb{R}^n$ to $\mathbb{R}^m$ implies $n =m$

Let $U, V$ be open sets in $\mathbb{R}^n, \mathbb{R}^m$, and let $f: U \rightarrow V$ be a bijective $C^{\infty}$ function whose inverse $g$ is also $C^{\infty}$. Show that $n = m$.

I think I have come up with a solution, and I wanted to know (i) is it correct and (ii) what are some other ways to think about this problem?

For $x = (x_1, ... , x_n) \in U$, I let $f_1, ... , f_m$ be the composition of $f$ with the projection functions, so

$$f(x) = (f_1(x), ... , f_m(x))$$

Similarly for $y = (y_1, ... , y_m) \in V$, I let $g_1, ... , g_n: U \rightarrow \mathbb{R}$ be the functions such that $g(y) = (g_1(y), ... , g_n(y))$.

The hypothesis is that $1_U = g \circ f$, so for each $i$, and all $x = (x_1, ... , x_n)$, we have

$$x_i = g_i(f_1(x_1, ... , x_n), ... , f_m(x_1, ... , x_n))$$

Applying $\frac{\partial}{\partial x_j}$ to both sides and using the chain rule, we have

$$\delta_{ij} = (\frac{\partial g_i}{\partial y_1} \circ f) \frac{\partial f_1}{\partial x_j} + \cdots + (\frac{\partial g_i}{\partial y_m} \circ f)\frac{\partial f_m}{\partial x_j}$$

And by the same argument using $f \circ g = 1_V$,

$$\delta_{ij} = (\frac{\partial f_i}{\partial x_1} \circ g) \frac{\partial g_1}{\partial y_j} + \cdots + (\frac{\partial f_i}{\partial x_n} \circ g)\frac{\partial g_n}{\partial x_j}$$

Fix a point $p = (p_1, ... , p_n) \in U$, and let $$q = f(p) = (f_1(p), ... , f_m(p)) = (q_1, ... , q_m)$$

so that also $p = (g_1(q), ... , g_n(q))$. Let $A$ be the $m$ by $n$ matrix $(\frac{\partial f_i}{\partial x_j}(p))$, and let $B$ be the $n$ by $m$ matrix $(\frac{\partial g_i}{\partial y_j}(q))$.

Then $AB$ is the $m$ by $m$ identity matrix, and $BA$ is the $n$ by $n$ identity matrix. So $n \geq \textrm{Rank}(B) \geq \textrm{Rank}(AB) = m$, and in the same way $m \geq n$.