Using Nakayamas lemma to prove that surjective implies injective.

So I have that $A$ is a commutative ring, and $f:M\rightarrow M$ is an $R$-linear endomorphism of $A$-module which is surjective. If I know that $M$ is finitely generated, I want to prove that $f$ is also injective.

This is what I have. Let $N=ker(f)$. Then we have that $N$ is finitely generated and moreover it is a submodule of $M$.I want to try to apply Nakayama's lemma to $N$. Meaning, I want to find an ideal $I$ of $A$ such that $I$ is contained in every maximal ideal and $IN=N$. This is where Im having trouble. For every ideal we obviously have that $IN\subset N$ ( because $f(in)=if(n)=i0=0)$, but I dont see what to make $I$ so that $N\subset IN$ and $I$ in every maximal ideal.

Thanks,

-
Sub-module of a f.g. module may fail to be finitely generated. Take $R=k[x_1,x_2,...]$ the ring of polynomials with infinitely many variable where $k$ is a field. $R$ over itself, is a f.g. module, generated by $1$, however, the ideal $I=(x_1,x_2,...)$ is not f.g. – Ehsan M. Kermani Dec 7 '12 at 7:43

Let $t$ be an indeterminate. We can define an $A[t]$-module structure on $M$, by defining the action of $t$ as follows: $tm = f(m)$, where $f$ is your surjective map. Then note that because $f$ is surjective, $(t)M = M$. In particular, we can apply the Cayley-Hamilton Theorem to the $A[t]$-module $M$ with the identity map on $M$. Then there exists $a_1, \dots, a_n \in (t)$ such that $(1 + a_1 + \dots a_n)M = 0$. Since each $a_j = tq_j(t)$ for some $q_j(t) \in A[t]$, we get a polynomial $q(t)$ such that $(1 - q(t)t)M = 0$. But, this means that $Id_M - q(f)f = 0$. Then $q(f)f = Id_M$, so $f$ is injective, and hence an isomorphism.
 My professor presented another version of Nakayama's lemma today whose proof relies on Cayley Hamilton and it is the statement that you use: If $M$ is f.g. and $I$ is an ideal of $R$ a commutative ring such that $IM=M$, then there exists an $a\in I$ such that $(1-a)M=0$. – Daniel Montealegre Dec 8 '12 at 5:36