Hiding the major revelations in spoiler quotes.
Suppose that $p\mid m^2+1$
Suppose for contradictory purposes that $p=4z+3$ for some $z\in\Bbb Z$.
Note that $p\not\mid m$ and $2\neq p$
This is because $4z+3$ is always odd. Further $k=m^2+1$ so $k\equiv 1\pmod{m}$ implying that $p\nmid m$ for any $p\mid k$.
Then $m^{p-1}\equiv 1\pmod{p}$ by fermat's little theorem.
Further, we know that $m^2+1\equiv 0\pmod{p}$ so $m^2\equiv -1\pmod{p}$
.
But then, that implies $m^{p-1}=m^{4z+2}=(m^2)^{2z+1}\equiv (-1)^{2z+1}\equiv -1\pmod{p}$
A contradiction.