a\cdot 2a\cdot\dots\cdot(p-1)a\equiv 1\cdot 2\cdot\dots\cdot(p-1)\pmod{p}\iff a^{p-1}(p-1)!\equiv(p-1)!\pmod{p}