The first step is to recognize that since each side of the triangle is a great circle (geodesic), a vector parallel transported along that geodesic experiences no rotation. The rotation occurs only at each vertex where the vector is rotated by an angle equal to 180 less the angle made by the two sides of the triangle. So the total angle of rotation after returning to its starting point is (180-a1 + 180 - a2 + 180 - a3). But since we know that a1 + a2 + a3 = 180 + gamma (where gamma is the difference you are looking for):
[tex]\theta = 540 - (180 + \gamma)) = 360 - \gamma[/tex]