Let $R$ be a PID. I want to show that if $P$ is a finitely generated left $R$-module and $P$ is isomorphic to $R^n$ and $R^m$ (as $R$-modules) for $n,m$ in the natural numbers, then $n=m$. I was wondering if the following proof is enough: Assume $m<n$. Let $f: R^m \to R^n$ be isomorphic. Then the image of the basis for $R^m$ generates $R^n$. But then $m$ elements generate $R^n$, showing that $m=n$.
I'm not that good at working with modules, so my question is, if this proof is valid?