To solve these kinds of questions, all we have to do is isolate a variable. In other words, we want to make sure that the variable is on side and all of the other numbers are on the other side. We can do this by essentially adding or subtracting both sides by a certain amount to get 0.
So:
5 = x + 8
To make sure x is only on one side, we simply subtract both sides by 8:
5 - 8 = x + 8 - 8
This makes
-3 = x
We can do it again for number 5:
-2 = p - 1
Add 1 to both sides this time, since it's -1.
-2 + 1 = p - 1 + 1
We get
-1 = p