Simple pulley system

Hey guys.
I have the following pulley system (in the pic).
I wrote down all the equations.
The thing I don't get is the accelerations equation (a1 = 2*a2). I understand that I can get to this equation somehow by the length of the rope, but how?
Thanks.