monitor doesn't work in single monitor configuration, but works fine with any other monitor connected
I have a monitor (LG 5K) which doesn't work correctly with my mac: it looks like the resolution provided by mac is not recognized by monitor: I can see the picture for a fraction of second and then it turned off, and then again and again. But the strange thing is that it doesn't work only in a single monitor configuration. If I connect another monitor or even connect iPad, monitor works just fine in full 5K resolution. But as soon as iPad or second monitor turned off, the first monitor enter this infinite loop of blinking again.
I've tried to boot in safe mode, nothing helps. I can't change the resolution while I can't see the picture, and as soon as I connect another monitor, everything works and changing resolution doesn't help at all.
I guess there is a configuration stored somewhere in system, which is separate for every monitor configuration. So the one with the only one monitor is bad. How can I reset it without reinstalling the entire OS?
Mac Mini Pro M2, Sonoma 14.5.
Mac mini (M2 Pro, 2023)