The BMW M3 became a legend in race driving. And it even managed to surprise sceptics who worried about the bottom line.