Negotiating a WiFi Gateway (ESP32 AP mode)

With multiple ESP32 devices all identically programmed, I'm trying to figure out how to negotiate a gateway so they are all on the same network, with the gateway becoming an AP.

Any help is appreciated, I'm really not seeing how this is done.

I can envision that 1 of them says "hey, I'll be gateway", then writes to EEPROM and reboots as the new gateway in AP mode, but I don't understand how to make that conversation happen. Being that there might only be 3 devices today, but 2 more tomorrow, I really can't hardcode anything.

If they all boot with identical network stats, can they bang each other out to start this conversation and without race conditions?

Again, I'm not a networking person, so any help is appreciated.