The passage from the first line to the second is not correct; the set of a's such that gcd(a,m) = 1 may not be disjoint from the gcd(a,n) = 1.
One suggestion: instead of working with the sums, try using Euler's formula for [tex]\varphi[/tex]:
[tex]\varphi\left(n\right) = n\left(\ 1 - \frac{1}{p_{1}}\right)\left(\ 1 - \frac{1}{p_{2}}\right)...\left(\ 1 - \frac{1}{p_{k}}\right)[/tex]
Where [tex]p_{1},...,p_{n}[/tex] are the prime factors of n.