The E39M5 has dual vanos and was legendary for CAT replacements... indeed, BMW put out a service update back in the day to dealers: DO NOT REPLACE CATS FOR CAT CODES.
The issue is that the vanos can cause AFR issues in different parts of the RPM bands- so when you look at idle, its fine...but at 5k it is hosed. The DME keeps compensating, you dont trip long term fuel trim codes, but the cars are getting loaded.
Oh, back in the day, there would be vanos codes...eventually the community learned DONT REPLACE THE VANOS, clean it. BMW would say 'replace it', sometimes under warranty- and after $12k in vanos hardware, including new solenoids, it would fix it. "yep, vanos was bad"
There are TONS of counterfeit MAFs ...they are crap. YMMV. even bosch branded and packaged.
Clean out your vanos solenoids. Take each out, use spray carb cleaner. Flush them hard WHILE ACTUATING THEM. (use 5V I believe, NOT 12! As least on the S62, these are controlled by the DME using regulated voltage. Some use a little 9V battery, which is safe too.) When you get them out, try to actuate them...listen to the sound, you want a nice, crisp snap. I have found they get fouled, oil sludge... then as you are flushing with cleaner the sound changes
Oh, ante wise, buy new orings. Will cost you 2 hours and $20 to clean the solenoids. Im not a betting man, but....