As the exercise says, the triangles are similar. So, we can set up proportions between correspondent sides.
In order to solve for x we can set up the proportion between the horizontal and vertical sides:

Solving this proportion for x implies 
Now you can solve for m and p using the pythagorean theorem, because both triangles are right:

Then, we know that the hypothenuse of the big triangle is m+p, so we have

which implies
