I drew a picture of part of the pentagon and square. If you extend the line of the pentagon as I did you get a right angle and a new angle which I called y.
This new angle 'y' is an exterior angle of the pentagon, and you can work out exterior angle of any shape by dividing 360 by the number of sides the shape has. So in this instance
y = 360 / 5 = 72 degrees.
As you know the sum of all angles in a triangle is 180 so:
x = 180 - 90 - 72
x = 18 degrees