2. Let $m$ be a given positive integer, then the largest positive integer $n$ such that $m^{2}+n$ divides $n^{2}+m$ is $\qquad$ .
2. $m^{4}-m^{2}+m$.

From the problem, we know that $\frac{n^{2}+m}{n+m^{2}} \in \mathbf{Z}$.
Since $\frac{n^{2}+m}{n+m^{2}}$
$=\frac{\left(n+m^{2}\right)^{2}-2 m^{2}\left(n+m^{2}\right)+m^{4}+m}{n+m^{2}}$
$=n+m^{2}-2 m^{2}+\frac{m^{4}+m}{n+m^{2}}$,
therefore, $\frac{m^{4}+m}{n+m^{2}}$ is a positive integer.
Thus, $n+m^{2} \leqslant m^{4}+m, n \leqslant m^{4}-m^{2}+m$.
Hence, the maximum value of $n$ is $m^{4}-m^{2}+m$.