The sum of the m numbers divided by m (which is the average) equals n^2. Then, the sum of the m numbers equals mn^2.
The sum of the n numbers divided by n (which is the average) equals m^2. Then, the sum of the n numbers equals nm^2.
The average of m+n numbers which is the sum of the m numbers plus the sum of the n numbers divided by (m+n) equals (mn^2+nm^2)/(m+n). This is mn(n+m)/(m+n). Then the factor (m+n) can be ruled out and the result is mn.