There have been problems reported with M1 and M2 Macs dropping internet signals when in densely packed areas. This can be resolved by turning AdrDrop and Bluetooth off, as they can cause interference. Beyond that, there isn’t much you can do other than switch to a wired connection.