In a course of group theory an exercise is left with no indications :
Let $A$ be an abelian group of finite type and $a_1,\dots ,a_n$ a $\mathbb{Z}$-basis of $A$. Let $f : A \to A$ be a group homomorphism. Les $M=(m_{ij})$ be the matrix (invertible) defined by $\displaystyle f(a_j)=\sum_{i=1}^n m_{ij}a_i$ with $\det (M)\neq 0$. Show that $[A:\operatorname{Im}(f)]=|\det M |$, i.e the index of $\operatorname{Im}(f)$ in $A$ as a subgroup is precisely $\det (M)$.
I am not able to prove this fact, and need a bit of help. In fact I do not see where I can make $\det (M)$ appear. Can you give me some hints ?
Thank you