Hello. I am completely stumped by this problem:

x = a1 (mod m1)

x = a2 (mod m2)

...

x = an (mod mn)

Let mj be arbitrary positive integers. Show that there is a simultaneous solution of this system if and only if ai= aj (mod(mi, mj)) for all pairs of the indices i,j for which 1 <= i < j <= r

Thanks for the help.