I have run into a problem which reads:

"Any finitely generated module $M$ over a commutative ring $R$ is Hopfian, i.e., any $R$-epimorphism from $M$ to itself is one-to one."

I think the problem could be associated with the following well-known fact:

"Let $R$ be a commutative ring, and $M$ be a finitely generated $R$-module. If $I$ is an ideal in $R$ with $M=IM$, then $(1-a)M=0$ for some $a\in I$."

I am stuck in finding the ideal $I$, and have no alternative try. Thanks for any help!