Strong magnetic fields near the event horizon of M87