Magnetic Field Rearrangement in the Photosphere Driven by an M5.0 Solar Flare