Use a flip-flop. Connect the clock to L2, and the input to L1. If the output is high, then it's L1-L2-L3, if low it's L1-L3-L2. (Obviously condition the signals so that they are compatible with the logic level flip-flop). If you add more flipflops in the same way, you can probably detect missing phases.