Compare the fractions 5/8 and 1/8. Note the only difference is the numerator changes. If we multiplied 5/8 by 1/5, then it becomes 1/8, as the '5's cancel out.
Multiply both sides by 1/5 and we get the following:
(5/8)m = 40
(1/5)*(5/8)m = (1/5)*40
(1/8)m = 8