In this case, we have two expressions with different coefficients, but identical unknowns.
So, we take the first expression, and subtract the second expression
(p2 + 4p - 23) - (3p2 - 23p -23)
The rule is to change the signs, and add.
So we get p2 + 4p - 23 - 3p2 + 23p + 23
When we combine the like terms, we get -2p2 + 27p,
which is usually written as 27p - 2p2