@user21820 Honestly, I think that requires a little bit of a "trick"---you have to know (or recognize that) the polynomial factors nicely, or you have to understand that $m=p$ is a solution. Both of these are things that make the job easier if you see the tricks, but my point was that if you don't see the trick, then you can still brute force it.
My answer was intended to point out that you can do things the hard way and that there is absolutely nothing mysterious going on.
I upvoted your answer, by the way---I like the solution, it just requires being slightly clever.