If $x$ is integral over $A_m$ for all maximal ideals $m$, then $x$ is integral over $A$ I am going over an old exam, and there is this question that I am stuck: 

Given $A$ a commutative ring with unity, show that if $x\in\operatorname{Frac}(A)$  is integral over $A_m$ for all maximal ideals $m$ of $A$, then $x$ is integral over $A$. 

Can anyone give me a hint please? 
 A: Consider the map of $A$-modules $f:\bar{A}\rightarrow \bar{A}[x]$, where $\bar{A}$ is the integral closure of $A$ in its field of fractions. This is onto if and only if $f_\mathfrak{m}:\bar{A}_\mathfrak{m}\rightarrow \bar{A}_\mathfrak{m}[x]$ is onto at all maximal ideals $\mathfrak{m}$ of $A$ (see for instance prop. 3.9 in Atiyah, MacDonald).  
A: For each $\mathfrak m$, choose an $f \notin \mathfrak m$ such that $x$ is integral over $A_f$ (for instance, a common multiple of the denominators of the coefficients in a minimal equation for $x$ over $A_\mathfrak m$). Then the $f_\mathfrak m$'s generate the unit ideal in $A$, since no maximal ideal can contain all $f_\mathfrak m$'s by construction. Let $f_1, \dots, f_n$ be a finite subset of the $f$'s which generates the unit ideal.
Let $M=A[x]\subseteq \text{Frac}(A)$, considered as an $A$-module. Then $M_{f_i} = A_{f_i}[x]$ is a finite $A_{f_i}$-module for each $i$, because $x$ is integral over $A_{f_i}$. Since the $f_i$'s generate the unit ideal, it follows by a standard "patching" argument that $M$ is itself a finite $A$-module, hence $x$ is integral over $A$.
