Mass air flow sensors measures the mass of air coming into the engine via a hot air film system or flap valve (not sure on the M5, I suspect a hot air film basis)
The engine management system then looks at the rpm and delivers the appropriate amount of fuel, via a programmed map. The advantages of mapping an engine (setting the fuelling) via these inputs is that the MAF sensor is self regulating to a degree - If the air is hot, the mass is less therefore less fuel, if the air pressure is less the mass is less therefore less fuel, etc
Race engines are mapped via throttle position and rpm with adjustments for air temp and pressure, this is much more responsive but not as emission friendly !